title: How to append a node in an XML file with node.js fast without string comparison
body: <p>A solution is proposed here: <a href="https://stackoverflow.com/questions/25886430/how-to-append-to-certain-line-of-file">How to append to certain line of file?</a></p>
  
  <p>I copy the solution here for reference</p>
  
  <pre><code>var fs = require('fs');
  
  var xmlFile;
  fs.readFile('someFile.xml', function (err, data) {
    if (err) throw err;
    xmlFile = data;
  
    var newXmlFile = xmlFile.replace('&lt;/xml&gt;', '') + 'Content' + '&lt;/xml&gt;';
  
    fs.writeFile('someFile.xml', newXmlFile, function (err) {
      if (err) throw err;
      console.log('Done!');
    }); 
  });
  </code></pre>
  
  <p>However the solution above requires string matching of the <code>'&lt;/xml&gt;'</code> string. If we know that the last line of the file will always be <code>'&lt;/xml&gt;'</code> is there any way to speed up the code by eliminating the need for string comparison? Is there an another more efficient way to do this task?</p>