tags:

views:

32

answers:

2

I'm trying to aggregate data from a number of different xml sources into a single xml file using either JavaScript or jQuery. I'm looping over the files, using jquery $.Ajax to read the file, and am selecting the first node (the node I want) and want to copy and append it to my destination xml file, then move on.

I can select the first row using:

firstRow = $(testThis.responseXML).find("z\\:row:eq(0)"); // get the first row
 alert('firstRow : ' + firstRow  );  // check the node text

But I can't seem to copy the node and append it. I'm trying to use:

newXMLData.append($(firstRow).text()); // append row to new xml file

I've tried using .text(), .HTML(), .val() but nothing seems to work.

Any ideas?

A: 

Have you tried simply newXMLData.append(firstRow)?

Here you have a good example about managing jquery and xml:

http://www.bennadel.com/blog/1054-jQuery-Demo-Working-With-XML-Documents.htm

Look how they find the rows: .find( "person[ type = 'girl' ]"), perhaps the problem is how you get that row with the Xpath sentence.

netadictos
Yes. it seems to break the script.
Chris G.
btw- I'm using this to create newXMLData: newXMLData= $("<?xml version='1.0' encoding='ISO-8859-1' ?><rs:data></rs:data>") ;
Chris G.
Ben's blog was part of my inspiration for this. It seemed so easy to create an xml source on the fly. Now, not so much.
Chris G.
also, he's appending text strings to the xml source. I'd have to pull all the node's attributes, create a new string, and add that. I thought for sure there's a simpler way.
Chris G.
A: 

try using the clone() method to get a copy of the node, I doubt that the same node could have 2 parents.

dvhh