title: extracting xml node(not text but complete xml ) and with other test nodes from xml file using SAX parser in java
body: <p>I have to read from large xml files each ranging ~500MB. The batch processes typically 500 such files in each run. I have to extract text nodes from it and <strong>at the same time extract xml nodes from it</strong>. I used xpath DOM in java for easy of use but that doesn't work due to memory issues as i have limited resources.</p>
  
  <p>I intent to use SAX or stax in java now - the text nodes can be easily extracted but i don't know how to extract xml nodes from xml using sax.</p>
  
  <p>a sample:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;Library&gt;
    &lt;Book name = "ABC"&gt;
      &lt;Author&gt;John&lt;/Author&gt;
      &lt;PrintingCompanyDT&gt;&lt;Printer&gt;Sam&lt;/Printer&gt;&lt;Printmachine&gt;Laser&lt;/Printmachine&gt;    
      &lt;AssocPrint&gt;Oreilly&lt;/AssocPrint&gt; &lt;/PrintingCompanyDT&gt;
    &lt;/Book&gt;
    &lt;Book name = "123"&gt;
      &lt;Author&gt;Mason&lt;/Author&gt;
      &lt;PrintingCompanyDTv&lt;Printervkelly&lt;/Printer&gt;&lt;Printmachine&gt;DOTPrint&lt;/Printmachine&gt;
      &lt;AssocPrint&gt;Oxford&lt;/AssocPrint&gt; &lt;/PrintingCompanyDT&gt;
    &lt;/Book&gt;
  &lt;/Library&gt;
  </code></pre>
  
  <p>The expected result:
  1)Book: ABC:<br/>
  Author:John
  <br/>PrintCompany Detail XML:</p>
  
  <pre><code>&lt;PrintingCompanyDT&gt;
    &lt;Printer&gt;Sam&lt;/Printer&gt;
    &lt;Printmachine&gt;Laser&lt;/Printmachine&gt;
    &lt;AssocPrint&gt;Oreilly&lt;/AssocPrint&gt; 
  &lt;/PrintingCompanyDT&gt;
  </code></pre>
  
  <p><br/>
  2) Book: 123<br/>
  Author : Mason<br/>
  PrintCompany Detail XML:</p>
  
  <pre><code>&lt;PrintingCompanyDT&gt;
    &lt;Printer&gt;kelly&lt;/Printer&gt;
    &lt;Printmachine&gt;DOTPrint&lt;/Printmachine&gt;
    &lt;AssocPrint&gt;Oxford&lt;/AssocPrint&gt;
  &lt;/PrintingCompanyDT&gt;
  </code></pre>
  
  <p><br/></p>
  
  <p>If i try in the regular way of appending characters in public void characters(char ch[], int start, int length) method
  I get the below <br/>
  1)Book: ABC:<br/>
  Author:John<br/>
  PrintCompany Detail XML : </p>
  
  <pre><code>Sam 
    Laser
        Oreilly
  </code></pre>
  
  <p>exactly the content and spaces.</p>
  
  <p>Can somebody suggest how to extract an xml node as it is from a xml file through SAX or StaX parser in java.</p>