R – Parsing AS3 XML objects

actionscript-3e4xxml

I am getting an object back from ASP.NET, and when tracing the XML it as follows:

var xml:XML = new XML(event.message.body);
trace(xml);

I get the following output:

<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://localhost:49329/">
    <string>One</string>
    <string>Two</string>
    <string>Three</string>
</ArrayOfString>

I am trying to iterate the structure to get the strings extracted, but to no avail. I am using the following code:

for each(var item:Object in xml.children())
{
    MonsterDebugger.trace(this, item.toString());
}

…and I know this is not entirely effective. It works now, but there is a way to get the strings with some syntax using the @ sign.

Can anyone please advise?

Best Answer

<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://localhost:49329/">
    <string>One</string>
    <string>Two</string>
    <string>Three</string>
</ArrayOfString>

You have to take care of the Namespace too:

var ns:Namespace = new Namespace("http://localhost:49329/");
var strings:XMLList = xml.ns::string;
for each(var str:XML in strings)
  trace(str.text());
Related Topic