0

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

2 Answers 2

1

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);
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you.... But based on some conditions I have to add more then one image tag inside the image tag......I think there is no optimized code for this.....
using these methods prependChild, appendChild, insertChildBefore and insertChildAfter you can achieve what do you want.
0

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.