Using jQuery to copy an XML node to another XML file? – Education Career Blog

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?

,

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

,

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.

Leave a Comment