n.bhv n.bhv - 25 days ago 8
Javascript Question

modify XML file using XMLDOM

I am not able to modify my xml using XMLSerializer...
My code is

var xml = request.responseText;
var DOMParser = require( 'xmldom' ).DOMParser;
var parser = new DOMParser();
var document = parser.parseFromString( xml, 'text/xml' );
document.getElementsByTagName( "a:Value" ).nodeValue = 12345;
var XMLSerializer = require( 'xmldom' ).XMLSerializer;
var serializer = new XMLSerializer();
var writetofile = serializer.serializeToString( document );
console.log( "writetofile" + writetofile );


I am getting XML with same old value not 12345.

Please let me know how to resolve this..tried all the options..still not working.:(

Answer

thanks for replying again ..appricited!!! I have found the solution,pasting here hopefully it will help others used textContent property change below line document.getElementsByTagName( "a:Value" ).nodeValue = 12345; to document.getElementsByTagName( "a:Value" )[0].textcontent = 12345;

it worked!!! now I am getting the entire XML with changed values. cheers!!