javascript - How to modify XML with JQuery -
i trying modify status flag in xml structure using javascript. using examples found on internet believe should work:
test = "<?xml version='1.0' encoding='utf-8' standalone='no' ?>" + "<resultaat>" + "<type>6</type>" + "<status>i</status>" + "<start_datum>2012-06-16 00:00:00</start_datum>" + "<eind_datum></eind_datum>" + "</resultaat>"
to change content of status field:
$(test).find("status").text("d")
the result test not modified , still contains old status i
thanks answers
the correct insight need convert xmlobject first , modify this.
below how ended doing it:
/* convert text xml object */ doc = $.parsexml(test) /* change fields required */ $(doc).find('status').text('d') /* text */ str = (new xmlserializer()).serializetostring(doc);
<p id="someelement"></p> <p id="anotherelement"></p> var xml = "<rss version='2.0'><channel><title>rss title</title></channel></rss>", xmldoc = $.parsexml( xml ), $xml = $( xmldoc ), $title = $xml.find( "title" ); /* append "rss title" #someelement */ $( "#someelement" ).append( $title.text() ); /* change title "xml title" */ $title.text( "xml title" ); /* append "xml title" #anotherelement */ $( "#anotherelement" ).append( $title.text() );
Comments
Post a Comment