尝试解析一些XML(我无法控制!)
在C#中,我会做类似的事情:
XmlNodeList xnList = xml.SelectNodes("/Names/Name[@type='M']");
可以在AS3中完成吗?
答案 0 :(得分:27)
简短回答,是的:
var xnList:XMLList = xml.Names.Name.(@type == "M");
更长的版本:
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())
有一个非常好的E4X tutorial on the Yahoo Developer Network。
HTH