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);

// trace
<my_xml>
  <row id="a" parent="a">
    <row id="b" parent="a"/>
    <row id="c" parent="a"/>
  </row>
  <row id="d" parent="d">
    <row id="e" parent="d"/>
    <row id="f" parent="d"/>
  </row>
</my_xml>

Kenneth Kawamoto
http://www.materiaprima.co.uk/

On 14/10/2011 17:34, Paul Andrews wrote:
On 12/10/2011 21:49, Kenneth Kawamoto wrote:
Not sure if this is the "best" way but you can do:

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

xml.row.(@id == "a").children = xml.row.(@id != "a");
xml.setChildren(xml.row.(@id == "a"));

trace(xml);

// trace
<my_xml>
<row id="a">
<row id="b"/>
<row id="c"/>
</row>
</my_xml>

Kenneth Kawamoto
http://www.materiaprima.co.uk/

Thanks - that works well and I hadn't considered using setChildren. It's
a great solution that shows my simplification was too simple!

If I have

<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>

but want

<my_xml>
<row id="a" parent="a">
<row id="b" parent="a"/>
<row id="c" parent="a"/>
</row>
<row id="d" parent="d">
<row id="e" parent="d"/>
<row id="f" parent="d"/>
</row>
</my_xml>

then it's closer to the real-life scenario and a bit harder.

Thanks for the solution.

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

Reply via email to