I am trying to modify a status flag in an XML structure using Javascript. Using examples found on the internet I believe this 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 the content of the status field:
$(test).find("status").text("D")
The result is however that test is not modified and still contains the old status I
Thanks for the answers
The correct insight is that you need to convert to an XMLObject first and modify this.
Below is how I ended up doing it:
/* Convert Text to XML Object */
doc = $.parseXML(test)
/* Change the fields required */
$(doc).find('status').text('D')
/* Back to Text */
str = (new XMLSerializer()).serializeToString(doc);
testis a string and you're not modifying it.