On 16/10/2011 13:01, Paul Andrews wrote:
On 16/10/2011 10:06, Kenneth Kawamoto wrote:
Here's one way:

var xml:XML = <my_xml>
<row id="a" parent="a" />
<row id="b" parent="a" />
<row id="c" parent="a" />

<row id="d" parent="d" />
<row id="e" parent="d" />
<row id="f" parent="d" />
</my_xml>;

var ids:Array = ["a", "d"];
for each (var s:String in ids){
    xml.row.(@id == s).children = xml.row.(@parent == s && @id != s);
while(xml.row.(@parent == s && @id != s).length()) delete xml.row.(@parent == s && @id != s)[0];
}

trace(xml);

Thanks Kenneth. That works very nicely. I appreciate you taking the time to do my little puzzle!

I made one change:

for each (var s:String in xml.row.(@id == @parent).@id){
    xml.row.(@id == s).children = xml.row.(@parent == s && @id != s);
while(xml.row.(@parent == s && @id != s).length()) delete xml.row.(@parent == s && @id != s)[0];
}

Thank you!

Ah, I went one stage further, which breaks the necessity for the parent to have @id == @parent:

var xml:XML = <my_xml>
<row id="a" parent="a" />
<row id="b" parent="a" />
<row id="c" parent="a" />

<row id="d" parent="d" />
<row id="e" parent="d" />
<row id="f" parent="d" />

<row id="g" parent="e" />
<row id="h" parent="e" />
<row id="i" parent="h" />
</my_xml>;

Scratching my head again..  !



Paul
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to