Skip to main content
rjoshicool
Inspiring
September 9, 2009
Question

Problem with creating XML from an XML file.

  • September 9, 2009
  • 1 reply
  • 330 views

I am having an XML file which I am reading in Flash/AS3. I store the loaded XML into a variable say: parentXML. From this parentXML, I am creating two XMLs say child1XML and child2XML, depending on certain conditions.

The problem I am facing is that when I change a property of a node in any XML, it gets changed in the other XMLs also, wherever it was added.

What I think is happening is that in actual no new node is getting added in the child XMLs, rather just the reference is getting added.
Any idea how I can resolve this issue? here is a snippet of the code I am using:

/* Creating child XML */
            for (var i:int = 0; i < parentXML.project.length(); i++)
            {
                for (var j:int = 0; j < parentXML.project.info.length(); j++)
                {
                    if (parentXML.project.info.@category == "something")
                    {
                        child1XML.appendChild(parentXML.project);
                    }
                }
            }
This topic has been closed for replies.

1 reply

September 9, 2009

Use the copy method:

            for (var i:int = 0; i < parentXML.project.length(); i++)
            {
                for (var j:int = 0; j < parentXML.project.info.length(); j++)
                {
                    if (parentXML.project.info.@category == "something")
                    {
                        child1XML.appendChild(parentXML.project.copy());
                    }
                }
            }

rjoshicool
Inspiring
September 9, 2009

Ya I tried that method just after posting the thread and it worked fine.. Thanks for replying..