I have a large XML file consisting of elements with a relatively fixed size i.e.
<rootElem>
<item>...</item>
<item>...</item>
<item>...</item>
<rootElem>
Item elements are relatively shallow and usually quite small (<100 KB), but there can be many (hundreds of thousands) of them. Elements are completely independent of each other.
How can I efficiently process a file in Java? I cannot read the whole file as a DOM, and I do not like to use SAX because the code becomes quite complicated. I would like to avoid splitting the file into smaller parts.
It would be best if I could get each element item , one at a time, as a separate DOM document that I could handle with the help of tools such as JAXB. Basically, I just want to loop once over all the elements.
I would think that this is a fairly common problem.
source
share