PDA

View Full Version : extract complete individual node from a XML file



Shaedo
November 8th, 2009, 10:54 AM
Hi,

I want to extract each individual node from and XML file. I want to preserve the node data AND the attribute name and the attribute data. In short create a new XML that is a copy of the complete node.

I am sure this is pretty simple but whilst I keep getting close I seem unable to get it to work!

Here is an example to illustrate:

If my XML file is like this (just an example)

<X>
<O A='1' Z='22' Q='13'>DataX</O>
<O A='54' B='25' C='16'>DataY</O>
<O G='47' F='38' C='19'>DataZ</O>
</X>

...and I load it and so on to the point where I would have this.

xd=new XML(e.target.data);
trace(xd)// traces out the XML file as above

What I want is to have something that would produce a trace like this:

<O A='1' Z='22' Q='13'>DataX</O>
-----
<O A='54' B='25' C='16'>DataY</O>
-----
<O G='47' F='38' C='19'>DataZ</O>
-----
from somthing like this:

for each (var x:XML in xd.O)
{
trace(x) // this is not it though
trace('------');
}

Thank you for your consideration,

S

senocular
November 8th, 2009, 12:29 PM
try trace(x.toXMLString())

Shaedo
November 8th, 2009, 07:52 PM
Nice! Thank you once again Senocular!

For completeness the function would then become:

for (var j:uint=0;j<xd.O.length();j++)
{
for each(var x:XML in xd..O[j])
{
trace(x.toXMLString());
trace('-----');
}
}