title: XML stream writer library in Node.js
body: <p>I have to generate single xml file by combining and processing multiple xmls of 100MB each approximately. I am not able to find any library of node.js which can stream write the xml. </p>
  
  <p>I tried below libraries</p>
  
  <ol>
  <li>xml-writer </li>
  <li>xmlbuilder</li>
  <li>genx</li>
  </ol>
  
  <p>All these library store the xml in memory which leads to out of memory exception.</p>
  
  <p>Do you have any suggestion for appropriate library which does not store complete object in memory.</p>
  
  <p>Example code for one of the library(xml-writer)</p>
  
  <pre><code>var fs = require('fs');
  var XMLWriter = require('xml-writer');
  
  var writeStream = fs.createWriteStream("myfile",{
      encoding: 'utf-8'
   });
  
  var xw = new XMLWriter(false);
  xw.startDocument('1.0', 'UTF-8').startElement(function() {
      return 'root';
  });
  for(var i = 0 ; i &lt; 10000000; i++ ) {
      xw.startElement(function() {
          return 'root1';
      }).text(function() {
          return 'Some content1';
      });
      xw.endElement();
  }
  xw.endElement();
  writeStream.write(xw.toString());
  writeStream.end();
  </code></pre>
  
  <p>This is simple code for adding two elements in the file. But it is giving me out of memory exception. As it is creating one object and then storing complete object in the memory and writing it at once in the file.</p>
  
  <p>I searched on google a lot but could not find any library which stream write the xml data to file.</p>
  
  <p>Thanks,</p>