I have a large XML file (many MBs) that I cannot afford to download as a whole.
<doc>
<element>...</element>
<element>...</element>
...
<element>...</element>
</doc>
I need to read this XML from the web (or better – stream it) and then take the first N elements from its body to have them processed with an XSLT template.
What library/technique do you recommend for such a task? I am writing in Java.
Kindest regards,
Q.
You can use STAX to read the elements and redirect a subset of them to a different stream:
Addition:
To write the closing tag, you should create a close tag event and pass it to same
XMLEventWriterobject whenever you need. For that you need an instance ofXMLEventFactory. Here’s example of writing a closing tag:P.S. Sorry for confusion with one of my comments suggesting to use
XMLStreamWriter. I had never usedXMLEventWriterso did not know how to use it properly until now.