id is an attribute, just like Key and last_login.
trace('id= '+node.firstChild.attributes['id']);
And since you're using AS3, you might as well use the new e4x syntax and forget
about XMLDocument (it's only there for backwards
compatibility):
var loader:URLLoader = evt.currentTarget as URLLoader;
var result:XML = new XML(loader.data);
trace("id: "[EMAIL PROTECTED]);
trace("key: "[EMAIL PROTECTED]);
trace("last_login: "[EMAIL PROTECTED]);
- use .currentTarget instead of .target
- use 'as' for casting
- use e4x with XML
regards,
Muzak
----- Original Message -----
From: "Paul Steven" <[EMAIL PROTECTED]>
To: "'Paul V.'" <[EMAIL PROTECTED]>; <[email protected]>
Sent: Monday, July 16, 2007 8:12 AM
Subject: [Flashcoders] Parsing XML data
>I am calling a script on a server and it is returning the following:
>
> <response stat="success">
> <session id="84cbd48179efb3a49a99bf8066ac3746" last_login="2007-07-17
> 06:32:58"
> key="99e5092715ddc304e08cc3392deee652b79442ce0d88fba606f97d46f857aa8f8a3801a
> 4799"/>
> </response>
>
> I am using AS3 and want to get the values of
>
> session id
> last_login
> key
>
> This is the code I am using but I cannot retrieve the value of "session id".
>
>
> var loader:URLLoader=URLLoader(event.target);
> var result:XML=new XML(loader.data);
> var myXML:XMLDocument=new XMLDocument();
> myXML.ignoreWhite=true;
> myXML.parseXML(result.toXMLString());
> var node:XMLNode=myXML.firstChild;
> trace('Key= '+node.firstChild.attributes['key']);
> trace('session id= '+node.firstChild.attributes['session id']);
> trace('last_login= '+node.firstChild.attributes['last_login']);
>
> I am thinking this is due to the space between "session" and "id" but I am
> not sure how to get this value. I do not have access to the server side to
> change "session id" to "session_id" which I imagine would fix it.
>
> Possibly there is an easy fix to my parsing code?
>
> Thanks in advance
>
> Paul
>
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com