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






On 11/10/2011 14:53, Paul Andrews wrote:
What's the best way to turn

this:

myXMLNode =
<my_xml>
< row id="a" />
< row id="b" />
< row id="c" />
</my_xml>;

into:

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

Using some E4X?

It's not so much a case of adding b and c as children of a, but of
removing them so I don't end up with:

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

Paul


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

Reply via email to