title: STAX to modify a nested XML with conditions and write back for Huge XML- around 6 GB
body: <p>I am a beginner to java and have been working on a code to unzip a zip file containing around 100 000 XML files and then merging those files into 1 XML file so that I can process one file instead of loading these many files.
  I unzipped the file and merged it into 1 file and parsed using DOM parser but now I need to modify this Merged XML file and then write it back in 1 file. I am able to do it using DOM parser and StringBuilder but looks like StringBuilder is not able to handle this big file as it gives java heap space error.</p>
  <p>As I did further research I understood STAX parser might be a good fit to handle large files with better performance.</p>
  <p>I have been going through multiple articles and tutorials but could not yet managed to write the code which can suffice my requirement.
  So, my XML has multiple tags, after merging I have a structure something like this:</p>
  <pre><code>&lt;Items&gt;
     &lt;Item &gt;
        &lt;Tag1&gt;
  &lt;/Tag1&gt;
           &lt;Tag2&gt;
  &lt;/Tag2&gt;
              &lt;Images&gt;
                 &lt;Image&gt;
                    &lt;width&gt;200&lt;/width&gt;
                    &lt;height&gt;200&lt;/height&gt;
                    &lt;url&gt;xyz.com&lt;/url&gt;
                    &lt;action&gt;update&lt;/action&gt;
                 &lt;/Image&gt;
                 &lt;Image&gt;
                    &lt;width&gt;400&lt;/width&gt;
                    &lt;height&gt;600&lt;/height&gt;
                    &lt;url&gt;xyz.com&lt;/url&gt;
                    &lt;action&gt;update&lt;/action&gt;
                 &lt;/Image&gt;
              &lt;/Images&gt;
     &lt;/Item&gt;
     &lt;Item &gt;
        &lt;Tag1&gt;
  &lt;/Tag1&gt;
           &lt;Tag2&gt;
  &lt;/Tag2&gt;
              &lt;Images&gt;
                 &lt;Image&gt;
                    &lt;width&gt;100&lt;/width&gt;
                    &lt;height&gt;400&lt;/height&gt;
                    &lt;url&gt;abc.com&lt;/url&gt;
                    &lt;action&gt;update&lt;/action&gt;
                 &lt;/Image&gt;
                 &lt;Image&gt;
                    &lt;width&gt;400&lt;/width&gt;
                    &lt;height&gt;200&lt;/height&gt;
                    &lt;url&gt;xyz.com&lt;/url&gt;
                    &lt;action&gt;update&lt;/action&gt;
                 &lt;/Image&gt;
              &lt;/Images&gt;
     &lt;/Item&gt;
  &lt;/Items&gt;
  </code></pre>
  <p>My requirement is to check if width and height under Image tag is greater than some value then only take Image Tag else delete it from Images section.
  Same way some other tags I will need to remove from the file and once all the processing is done return the whole XML file back with changes.</p>
  <p>I went through many articles for STAX implementation but I could not get myself clear on how to access Image tag which is kind of great grandchild of root tag &lt;Items&gt;.</p>