AS3: How to get all XML-Nodes with a special attribute? (With sourch)
- by insnet
Hi there
The Challenge:
i d like to collect all nodes with the attribute "id".
The Problem:
The code doenst work with nested nodes.
<?xml version="1.0" encoding="utf-8"?><contentmap><fonts id="fonts">
fonts/Arial.swf
swf/library_main.swf
private function onXMLLoader(event : Event) : void {
_xml = _loader.getXML(event.target.url.url);
var searchTerms : XMLList = _xml.*.(hasOwnProperty('@id'));
if (searchTerms.length() 0 ) {
_NodeArray = new Array();
_parseNode(searchTerms);
}
private function _parseNode(xml : XMLList) : void {
for each (var node: XML in xml) {
if(!node.hasSimpleContent()) {
_parseNode(node.children());
} else {
var nodeObject : Object = new Object();
nodeObject['value'] = node.text();
for each(var a:XML in node.@*) {
var name : String = String(a.name());
nodeObject[name] = a.toXMLString();
}
_NodeArray.push(nodeObject);
}
}
}