I am trying to insert child node in xml via actionscript as follow –
var xml:XML = <menu>
<item>burger</item>
<item>soda</item>
</menu>;
xml.insertChildAfter(xml.item[0], <item>fries</item>);
trace(xml);
----------output---------------
<menu>
<item>burger</item>
<item>fries</item>
<item>soda</item>
</menu>
-------------------------
the above code is working fine as expected, but when i am trying to insert a child in nested child, i am unable to insert.
but below is not working-
var xml:XML = <menu>
<my>
<item>burger</item>
<item>soda</item>
</my>
</menu>;
xml.insertChildAfter(xml.my.item[0], <item>fries</item>);
trace(xml);
------------output-------------
<menu>
<my>
<item>burger</item>
<item>soda</item>
</my>
</menu>
moreover it returns undefined and as described in actionscript livedocs –
If you call this method on an XML child that is not an element (text, attributes, comments, pi, and so on) undefined is returned.
any help/input is greatly appreciated, thanks for stopping by.
The first parameter of
insertChildAftermust be a direct child of the XML node you are calling the method on. So try: