2009-08-20 5 views
0

Le défi:AS3: Comment obtenir tous les nœuds XML avec un attribut spécial? (Avec sourch)

i d aime rassembler tous les nœuds avec l'attribut "id".

Le problème:

Le code ne fonctionne pas avec des noeuds imbriqués.

<?xml version="1.0" encoding="utf-8"?> 
<contentmap> 
    <fonts id="fonts"> 
    <font id="Arial" name="RicolaArial">fonts/Arial.swf</font> 
    </fonts> 
    <plugin id="library_main" name="theName">swf/library_main.swf</plugin> 
</contentmap> 

.

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 [email protected]*) { 
     var name : String = String(a.name()); 
     nodeObject[name] = a.toXMLString(); 
     } 
     _NodeArray.push(nodeObject); 
    } 
    } 
} 

Répondre

1

il suffit d'utiliser _xml .. @ id

Questions connexes