简体   繁体   中英

How can I append data to my XML document with JQUERY?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM