Solved

Parsing XML in Flash from Webservice connector

Posted on 2008-06-20
14
425 Views
Last Modified: 2013-11-19
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! ;)

0
Comment
Question by:winstonbr
  • 8
  • 6
14 Comments
 
LVL 5

Expert Comment

by:cwickens
ID: 21845366
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/
0
 

Author Comment

by:winstonbr
ID: 21846290
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

0
 
LVL 5

Accepted Solution

by:
cwickens earned 500 total points
ID: 21846632
oh, sorry.  I missunderstood the question.  

Try this:

var Drop = new Array();
function Convert () {
XMLString = "<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>";
docXML = new XML(XMLString);
XMLDrop = docXML.childNodes;
XMLChannelGuid = XMLDrop[0].childNodes;
XMLChannelNo = XMLDrop[1].childNodes;
XMLDisplayName = XMLDrop[2].childNodes;
XMLDesc = XMLDrop[3].childNodes;
XMLStatusMessage = XMLDrop[4].childNodes;
0
 

Author Comment

by:winstonbr
ID: 21847142
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


0
 
LVL 5

Expert Comment

by:cwickens
ID: 21847326
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?
0
 

Author Comment

by:winstonbr
ID: 21847609
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..
0
 
LVL 5

Expert Comment

by:cwickens
ID: 21847941
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?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:winstonbr
ID: 21848592
Sorry, I am calling a WSDL file from the server using the WEB SERVICE CONNECTOR to pull out the results

hope this helps

0
 
LVL 5

Expert Comment

by:cwickens
ID: 21849176
0
 

Author Comment

by:winstonbr
ID: 22104004
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! ;)
0
 

Author Comment

by:winstonbr
ID: 22104780
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?
0
 
LVL 5

Expert Comment

by:cwickens
ID: 22152359
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
0
 

Author Comment

by:winstonbr
ID: 22169938
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

0
 

Author Comment

by:winstonbr
ID: 22172753
FOLLOWUP:

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now