I'm having some trouble replacing text inside an XML node in Node.js (v0.12.0). The "nodeValue" property appears to let me read the text from the node, but not change it.
I'm using the node modules "xpath.js" (1.0.6) and "xmldom" (0.1.19)
My code:
// Use xpath.js and xmldom to fetch the "metadata" node
var doc = new Parser().parseFromString(jobXml, 'application/xml');
var nodes = select(doc, '/job/metadata/metafield[@name="metadata"]');
var metaNode = nodes[0];
console.log(metaNode.firstChild.nodeValue); // Output is "hello"
metaNode.firstChild.nodeValue = 'world'; // Replace "hello" with "world"
console.log(metaNode.firstChild.nodeValue); // Output is now "world"
var result = new Serializer().serializeToString(doc);
console.log(result); // text has reverted to "hello"
I've put together a runnable.com project demonstrating this behaviour:
http://runnable.com/VWw18wFQKv46Ng_V/sean-s-sandbox-for-node-js-and-hello-world
Can anyone spot what I'm doing wrong? Is there another way to achieve this?