title: Replacing text in an XML node in node.js
body: <p>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.</p>
  
  <p>I'm using the node modules "<a href="https://www.npmjs.com/package/xpath.js" rel="nofollow">xpath.js</a>" (1.0.6) and "<a href="https://github.com/jindw/xmldom" rel="nofollow">xmldom</a>" (0.1.19)</p>
  
  <p>My code:</p>
  
  <pre><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"
  </code></pre>
  
  <p>I've put together a runnable.com project demonstrating this behaviour:</p>
  
  <p><a href="http://runnable.com/VWw18wFQKv46Ng_V/sean-s-sandbox-for-node-js-and-hello-world" rel="nofollow">http://runnable.com/VWw18wFQKv46Ng_V/sean-s-sandbox-for-node-js-and-hello-world</a></p>
  
  <p>Can anyone spot what I'm doing wrong? Is there another way to achieve this?</p>