|
Categories
|
|
|
|
|
|
Parsing an XML Packet in Flash
|
|
Published
06/19/2006
|
Macromedia Flash
|
|
|
|
|
|
Parsing an XML Packet in Flash - // if the XML packet was a simple packet using attributes.
- var login_xml:XML = new XML("<?xml version=\"1.0\" ?><login status=\"success\" sessionid=\"57754B095346D64A\" />");
- trace("status: "+login_xml.firstChild.attributes.status);
- trace("sessionid: "+login_xml.firstChild.attributes.sessionid);
- trace("");
- // if the XML packet had child nodes.
- var login_xml:XML = new XML("<?xml version=\"1.0\" ?><login><status>success</status><sessionid>57754B095346D64A</sessionid></login>");
- trace("status: "+login_xml.firstChild.childNodes[0].firstChild.nodeValue);
- trace("sessionid: "+login_xml.firstChild.childNodes[1].firstChild.nodeValue);
- trace("");
- // parse XML packet using a for loop to loop over the childNodes
- var login_xml:XML = new XML("<?xml version=\"1.0\" ?><login><status>success</status><sessionid>57754B095346D64A</sessionid></login>");
- for (var i = 0; i<login_xml.firstChild.childNodes.length; i++) {
- trace(login_xml.firstChild.childNodes[i].nodeName+": "+login_xml.firstChild.childNodes[i].firstChild.nodeValue);
- }
|