Reputation: 165
My XML is
<imglist>
<url>data</url>
<title>title</title>
</imglist>
Here, I want insert <image></image>
this tag. which means I need the output like
<imglist>
<image>
<url>data</url>
<title>title</title>
</image>
</imglist>
Any answers????
Upvotes: 0
Views: 138
Reputation: 2223
Nodes can be created dynamically simply by referencing them. If you reference a node that doesn't exist it will be created for you like:
var xml:XML = <imglist><url>data</url><title>title</title></imglist>;
xml.image = "myimage";
//node image now exist
//you can also remove nodes this way:
delete xml.image;
Upvotes: 0
Reputation: 2359
I do recommend this URL, with official API and explanation about how to assembling and transforming XML objects.
You have the prependChild() method or the appendChild() method to add a property to the beginning or end of an XML object’s list of properties. Also the insertChildBefore() method or the insertChildAfter() method to add a property before or after a specified property.
You can also use curly brace operators ( { and } ) to pass data by reference (from other variables) when constructing XML objects.
A quick solution (not telling you that is the best) for your answer:
var xml:XML = <imglist><url>data</url><title>title</title></imglist>;
var newXML:XML = <imglist><image>{xml.url}{xml.title}</image></imglist>
trace(newXML);
Upvotes: 1