Skip to content Skip to sidebar Skip to footer

How To Convert Xml Document Object To String?

I have xml that I have in a string. I want to change some attributes in it. So what I have done is var xml //contains xml parser = new DOMParser() xmlDoc = parser.parseFromStr

Solution 1:

You will need to serialize your xmlDoc back to XML once you have made the changes:

var s = new XMLSerializer();
var newXmlStr = s.serializeToString(xmlDoc);

Now you can do what you need to do with the string of updated XML, overwrite your xml variable, or send it to the server, or whatever...

See the MDN docs for further info

Post a Comment for "How To Convert Xml Document Object To String?"