dom - Return edited XML string with Javascript -


i'm using the xml < script > library w3c dom parser available here. (this because i'm using js inside .net cli jint program instead of browser.)

my problem is, edit xml using domimplementation.loadxml() function , edit 1 node value, want retrieve string xml including modified one:

 //instantiate w3c dom parser  var parser = new domimplementation();   //load xml parser , domdocument  var domdoc = parser.loadxml($xmldata);   //get root node (in case, rootnode)  var docroot = domdoc.getdocumentelement();   // change "name" element value  docroot.getelementsbytagname("name").item(0).nodevalue="john";   // try retreive xml including changed 1  $xmldata=docroot.getxml(); 

sample xml:

<name>carlos</name> 

all works except last line:

docroot.getxml(); 

which returns original xml string , not modified one.

any idea how can retreive xml string including modified?

fixed replacing:

docroot.getelementsbytagname("name").item(0).nodevalue="john"; 

by:

docroot.getelementsbytagname("name").item(0).firstchild.setnodevalue("john"); 

seems needed call firstchild text in element "name" replaced. docroot.getxml() returned xml code including modified one.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -