Link to home
Start Free TrialLog in
Avatar of winstonbr
winstonbr

asked on

Parsing XML in Flash from Webservice connector

I am not an expert in Flash for this type of programming so please bear with me.

I have created a flash file that uses the WebServiceConnector component from Flash (FLASH 8). I can call the XML file successfully and I can see the results as one entire XML file in my test TEXT area on the screen. This is working perfectly fine..

I need to find a way to take that result (currently bound in a string, called outputSt:text) and parse this information properly into an XML object (I believe that is what it is called)

I have looked over the Q & A's within this site, and although very great and insightful, I can not seem to get my parsing going unless I use Actionscript (which I would prefer to use the WebServiceConnector, unless Actionscript is WAY better)

can someone please show me a way to do this with an example? using a simple

Here is what I see when I successfully call my WebServiceConnector and the WSDL file. Results are shown between the ####### marks.

#########

ÿ<?xml version="1.0" encoding="utf-8"?><ServiceCallReturnXml

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://fakeurl.com">

<ErrorCode>0</ErrorCode>

<Xml>
<Channels>


<Channel>
<ChannelGuid>65c577cb-84d8-4b74-89b2-34c7630807b2</ChannelGuid>
<ChannelNo>1</ChannelNo>
<DisplayName>Internal Demo Channel</DisplayName>
<Description>For Development and Internal Demoing of New Features</Description>
<StatusMessage>Active</StatusMessage>
</Channel>

<Channel>
<ChannelGuid>4b4836c2-8740-49fe-af8c-1694b990eedf</ChannelGuid>
<ChannelNo>2</ChannelNo>
<DisplayName>Client Demo Channel</DisplayName>
<Description>Client Presentation Channel to Demo Available Features</Description>
<StatusMessage>Active</StatusMessage>
</Channel>

<InformationText>Information text goes here...</InformationText>
</Channels>

</Xml>
</ServiceCallReturnXml>

#########

This is the result I see within my bound TEXTAREA of "results" Text area. I need to be able to parse this info into an XML Object I believe from what I have read on this site.

I hope I came to the right place! ;)

Avatar of cwickens
cwickens
Flag of United States of America image

For the overview of parsing XML, this is my one-stop-shop:
http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary827.html

The basic example I have used a number of times:
http://www.oman3d.com/tutorials/flash/xml/
Avatar of winstonbr
winstonbr

ASKER

This is great information, however it does not answer my question above.

I can pull in the XML file perfectly fine from the server using the WSDL file. I have it come through the WebServiceConnector using WSDL, and I can see the results listed above in and XML format on the screen in a TEXT AREA component.

MY question is: How do I take that "string file" currently defined in my code as myText:text ,  that contains the XML output listed above and use the XML methods that you have sent me a link for above, and use this information as if the XML loaded already.. I do not want to use ".load("myfile2.xml") here as the XML has already been loaded.

And most importantly, how do I parse the information.. would I use the normal methods as shown in the XML files above and seeing that  the file has been successfully loaded, so how do I skip the (Success) function and just get to the parsing?

An example would be great

ASKER CERTIFIED SOLUTION
Avatar of cwickens
cwickens
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is close, but still not there. I see how you are doing this and it's great.. so i'll edit my question a bit

I currently see the ENTIRE XML FILE in my TEXT AREA and it is defined in myText:text, as a string.. the ENTIRE XML that I see is listed above between the #### marks. This is what I see on my Flash screen if I use a Variable and a Text area to view my results

In the programming above you have an "XML string" right after the Function,  and have put in quotes all the Text in the XML that is to be found between the <xml> lines.  This is what I want as an end result..

 however I am looking for the script  that can find and remove these particular  lines from the myText:text:string, as you have placed it in quotes

"<Channel>
<ChannelGuid> 65c577cb-84d8-4b74-89b2-34c7630807b2</ ChannelGuid >
< ChannelNo ><b>AAA</b></ChannelNo >
<DisplayName>Internal Demo Channel</DisplayName>
<Description>For Development and Internal Demoing of New Features</Description>
<StatusMessage>Active</StatusMessage>
</Channel>";

and pull this content out and place into the function you have just sent.

Sorry that I didn't describe it well enough, but it's on the right track


no problem, I will have to work on it a bit.  you only want what I 'stripped' out of what you have in the text area, right?

Ok, what does your ActionScript look like that loads the text initially into the text box?
all I do is this:

myDisplayedText = myText.text;

That will pull the XML file string that was placed in the myText string and place it on the Flash application so I can see it. I only did this so I could see the results.

essentially, the "myText" contains the entire XML file and what I want stripped out is this area of that XML

<Channel>
<ChannelGuid> 65c577cb-84d8-4b74-89b2-34c7630807b2</ ChannelGuid >
< ChannelNo ><b>AAA</b></ChannelNo >
<DisplayName>Internal Demo Channel</DisplayName>
<Description>For Development and Internal Demoing of New Features</Description>
<StatusMessage>Active</StatusMessage>
</Channel>

thanks..
ok, how is it that you are getting the xml, are you just pasting it in there in the actions panel or are you loading the WSDL file?

Or more simply, how are you populating the "myText" variable?
Sorry, I am calling a WSDL file from the server using the WEB SERVICE CONNECTOR to pull out the results

hope this helps

Hi

I have played with this and I am very frustrated as it is not working.

This is the XML string that comes in:

<?xml version="1.0" encoding="utf-8"?><ServiceCallReturnXml

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://fakeurl.com">

<ErrorCode>0</ErrorCode>

<Xml>
<Channels>


<Channel>
<ChannelGuid>65c577cb-84d8-4b74-89b2-34c7630807b2</ChannelGuid>
<ChannelNo>1</ChannelNo>
<DisplayName>Internal Demo Channel</DisplayName>
<Description>For Development and Internal Demoing of New Features</Description>
<StatusMessage>Active</StatusMessage>
</Channel>

<Channel>
<ChannelGuid>4b4836c2-8740-49fe-af8c-1694b990eedf</ChannelGuid>
<ChannelNo>2</ChannelNo>
<DisplayName>Client Demo Channel</DisplayName>
<Description>Client Presentation Channel to Demo Available Features</Description>
<StatusMessage>Active</StatusMessage>
</Channel>

<InformationText>Information text goes here...</InformationText>
</Channels>

</Xml>
</ServiceCallReturnXml>

+++++++++++++++++++++++++++=

What I need to know is how you convert this STRING into an XML

Can someone please help me to figure this out. it really can't be this hard?

The FUNCTION CONVERT() above seems like a good thing, but with the XML laid out like this, I need the EXACT fix to work.. I am not good with XML but it is not working

please.. I am tearing my hair out with this one.

I know you guys can do this! ;)
Follw up:
The Webservice calls the XML file and then I get it into the system. once that is done, it gets stored as a TEXT string. So I can see the XML file inside that Text string. how I then parse it down?
In AS2, you would set variables for each node in the XML file.  

Kirupa has a good tutorial that shows how to (with solid explainations) iterate through the XML and set variables for the values of each node.  It sounds like you are really close and this should sort out the rest...

http://www.kirupa.com/web/xml/XMLwithFlash3.htm

I hate to send you to another site but I am slammed on another project atm.
c
thanks

I am still very much stuck.... I have posted something below that might be easy to code but I can't think straight anymore ;(

. I just can't seem to understand how after I use the Webservice and Bind it to a component (like a text area, since I don't know where else to bind it to) and I can see the XML file if I trace it in a string format, how I can convert that to a variables. I tried your first option with the XMLDROP system, but I keep getting UNDEFINED when I run it on my XML file.

Here is another one to review to help me grab the variable from here: This is my first XML file I pull from the Webservice.

<?xml version="1.0" encoding="utf-8"?>
<ServiceCallReturnXml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://fakeurl.com">
      <ErrorCode>0</ErrorCode>
      
      <Xml>
      
            <PlayerInfo>
                  <UserId>6809dfac-3069-4408-8b49-9dae22faabcb</UserId>
                  <LoginName>tigerwoods</LoginName>
                  <Password />
                  <FirstName>Tiger</FirstName>
                  <LastName>Woods</LastName>
                  <CurrentPoints xsi:type="xsd:int">0</CurrentPoints>
            </PlayerInfo>
      
      </Xml>
</ServiceCallReturnXml>


______

now, is the SERVICECALLRETURN XML
 considered Parent or Child?

I have tried this  to grab the USER ID but this doesn't work:

my_xml.firstChild.firstChild[1].firstChild;

What am I doing wrong ;(

if someone could answer this, I believe me solution will be found

FOLLOWUP:

Can you show the example using the XMLDROP function you posted above.