0

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?

josef.van.niekerk
  • 11,941
  • 20
  • 97
  • 157

3 Answers3

2

You've pretty much got it. Should be able to write the same loop like so:

for each( var el:XML in xml.string ) {
  trace( el.toString() );
}

Take a look at these e4x docs, these are for Flex, but it all applies because it's just AS3. As you can see the state of documentation on a lot of this stuff is a little flaky :)

rfunduk
  • 30,053
  • 5
  • 59
  • 54
1
<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());
Amarghosh
  • 58,710
  • 11
  • 92
  • 121
0

You can read my answer to AS3 - Deepest XML Elements By using SimpleXML you can parse your XML in an easy to use manner.

Community
  • 1
  • 1
RaamEE
  • 3,017
  • 4
  • 33
  • 53