0

I'm trying to append some text to an XML document that I'm working on.

First I'm creating a string that I use $.parseXML to convert it to an xml document.

Now I need to append some data to that document.

I have the following code.

this.dataXML = "<webdata></webdata>";  --- That is setup on another function and I need 
                                        to append to that file.

tempXML = $.parseXML(this.dataXML);
var tempDATA = "<test>123</test><test>456</test>";
$(tempXML).find("webdata").append(tempDATA);  --- DOES NOT WORK

I also tried to do the following

$(tempXML).find("webdata").append($.parseXML(tempDATA)); 

I need to append the tempDATA to the dataXML.

Ennio
  • 1,147
  • 2
  • 17
  • 34
  • possible duplicate of [How do I get the entire XML string from a XMLDocument returned by jQuery (cross browser)?](http://stackoverflow.com/questions/1675027/how-do-i-get-the-entire-xml-string-from-a-xmldocument-returned-by-jquery-cross) – emerson.marini Oct 17 '14 at 20:52

1 Answers1

0

You can achieve this using jQuery:

var data = "<webdata></webdata>",
    $xml = $( data ),
    data = "<test>123</test><test>456</test>";

$xml.append(data);

jsFiddle Demo

In the Fiddle, ignore the outerHTML() function - that's just to debug the code so you can see the entire XML structure.

BenM
  • 52,573
  • 26
  • 113
  • 168
  • That helped thanks.. now can I do something like( 'data = $xml;' ) this to set data with the current xml? – Ennio Oct 20 '14 at 18:06