title: Node.js Example to convert Xml to JSON for large Xml file
body: <p>I'm relatively new to Node.js. I'm trying to convert 83 XML files that are each around 400MB in size into JSON. </p>
  
  <p>Each file contains data like this (except each element has a large number of additional statements):</p>
  
  <pre><code>&lt;case-file&gt;
    &lt;serial-number&gt;75563140&lt;/serial-number&gt;
    &lt;registration-number&gt;0000000&lt;/registration-number&gt;
    &lt;transaction-date&gt;20130101&lt;/transaction-date&gt;
    &lt;case-file-header&gt;
       &lt;filing-date&gt;19981002&lt;/filing-date&gt;
       &lt;status-code&gt;686&lt;/status-code&gt;
       &lt;status-date&gt;20130101&lt;/status-date&gt;
    &lt;/case-file-header&gt;
    &lt;case-file-statements&gt;
       &lt;case-file-statement&gt;
          &lt;type-code&gt;D10000&lt;/type-code&gt;
          &lt;text&gt;"MUSIC"&lt;/text&gt;
       &lt;/case-file-statement&gt;
       &lt;case-file-statement&gt;
          &lt;type-code&gt;GS0351&lt;/type-code&gt;
          &lt;text&gt;compact discs&lt;/text&gt;
       &lt;/case-file-statement&gt;
    &lt;/case-file-statements&gt;
    &lt;case-file-event-statements&gt;
       &lt;case-file-event-statement&gt;
          &lt;code&gt;PUBO&lt;/code&gt;
          &lt;type&gt;A&lt;/type&gt;
          &lt;description-text&gt;PUBLISHED FOR OPPOSITION&lt;/description-text&gt;
          &lt;date&gt;20130101&lt;/date&gt;
          &lt;number&gt;28&lt;/number&gt;
       &lt;/case-file-event-statement&gt;
       &lt;case-file-event-statement&gt;
          &lt;code&gt;NPUB&lt;/code&gt;
          &lt;type&gt;O&lt;/type&gt;
          &lt;description-text&gt;NOTICE OF PUBLICATION&lt;/description-text&gt;
          &lt;date&gt;20121212&lt;/date&gt;
          &lt;number&gt;27&lt;/number&gt;
       &lt;/case-file-event-statement&gt;
     &lt;/case-file-event-statements&gt;
  </code></pre>
  
  <p></p>
  
  <p>I have tried a lot of different Node modules, including sax, node-xml, node-expat and xml2json. Obviously, I need to stream the data from the file and pipe it through an XML parser and then convert it to JSON. </p>
  
  <p>I have also tried reading a number of blogs, etc. attempting to explain, albeit superficially, how to parse Xml.</p>
  
  <p>In the Node universe, I tried sax first but I can't figure out how to extract the data in a format that I can convert it to JSON. xml2json won't work on streams. node-xml looks encouraging but I can't figure out how it parses chunks in any manner that makes sense. node-expat points to libexpat documentation, which appears to requires a Ph.D. Node elementree does the same, pointing to the Python implementation but doesn't explain what has been implemented or how to use it. </p>
  
  <p>Can someone point me to example that I could use to get started?</p>