Flash / Flex / ActionScript/XML/XML hierarchy
Версия от 09:19, 26 мая 2010; (обсуждение)
Find data nested deep within an XML tree.
package{
import flash.display.Sprite;
public class Main extends Sprite{
public function Main(){
var myXML:XML = <alpha>
<beta>
<charlie delta="echo">foxtrot</charlie>
</beta>
<beta>
<golf hotel="india">juliet</golf>
</beta>
</alpha>;
trace(myXML.beta[1].golf); // Displays: juliet
trace(myXML.beta[0].charlie.@delta); // Displays: echo
}
}
}
Returns the root of an XML hierarchy, relative to a given child
package{
import flash.display.Sprite;
public class Main extends Sprite{
public function Main(){
getRoot(someChild);
}
public function getRoot (childNode:XML):XML {
var parentNode:XML = childNode.parent( );
if (parentNode != null) {
return getRoot(parentNode);
} else {
return childNode;
}
}
}
}