views:

92

answers:

1

Trying to parse some XML (over which I have no control!)

In C# I would do something like:

XmlNodeList xnList = xml.SelectNodes("/Names/Name[@type='M']");

Can this be done in AS3?

+5  A: 

short answer, yes:

var xnList:XMLList = xml.Names.Name.(@type == "M");

longer version:

var xml:XML = <Root>
        <Names>
            <Name type="M" value="John Doe" />
            <Name type="F" value="Jane Doe" />
            <Name type="M" value="John Hancock" />
        </Names>
        <Other />
      </Root>

var xnList:XMLList = xml.Names.Name.(@type == "M");

//test
for each (var xnNode:XML in xnList) trace(xnNode.toXMLString())

There's a pretty good E4X tutorial on the Yahoo Developer Network.

HTH

George Profenza
+1 good answer.
gmale
+1 for the answer
o15a3d4l11s2