It's very hackish, but here we go :)
Say you have this recursive function:
private function transformXMLWithParentCount(original:XML, xml:XML,
n:uint):void {
for(var i:uint = 0, len:uint = xml.children().length(); i < len; i++){
original..*.(@att == xml.children()[...@att)....@parent = n;
transformXMLWithParentCount(original, xml.children()[i], n + 1);
}
}
You have this XML:
var testXML:XML = <root>
<person att="1">
<person att="2">
<person att="3"/>
<person att="4"/>
</person>
</person>
<person att="5">
<person att="6">
<person att="7"/>
<person att="8"/>
</person>
</person>
</root>;
Then:
transformXMLWithParentCount(testXML, testXML, 0);
trace(testXML);
You should get:
<root>
<person att="1" parent="0">
<person att="2" parent="1">
<person att="3" parent="2"/>
<person att="4" parent="2"/>
</person>
</person>
<person att="5" parent="0">
<person att="6" parent="1">
<person att="7" parent="2"/>
<person att="8" parent="2"/>
</person>
</person>
</root>
--
Kenneth Kawamoto
http://www.materiaprima.co.uk/
On 22 March 2010 16:27, Lehr, Theodore <[email protected]> wrote:
> I am still trying to find a way to see where a child is within the xml - on
> what level... is it possible to count a nodes parents?
>
> So if I had:
>
> <person att="1">
> <person att="2">
> <person att="3"/>
> <person att="4"/>
> </person>
> </person>
>
> 1 would return that it has 0 parents, 2 would say it has 1 parent, 3 & 4
> would say they have 2 parents....
>
> hope that makes sense....
>
> Ted
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders