How to access a subset of XML data in Java when the XML data is too large to fit in memory?
Posted
by Michael Jones
on Stack Overflow
See other posts from Stack Overflow
or by Michael Jones
Published on 2010-05-10T11:17:46Z
Indexed on
2010/05/10
11:24 UTC
Read the original article
Hit count: 179
What I would really like is a streaming API that works sort of like StAX, and sort of like DOM/JDom.
It would be streaming in the sense that it would be very lazy and not read things in until needed. It would also be streaming in the sense that it would read everything forwards (but not backwards).
Here's what code that used such an API would look like.
URL url = ...
XMLStream xml = XXXFactory(url.inputStream()) ;
// process each <book> element in this document.
// the <book> element may have subnodes.
// You get a DOM/JDOM like tree rooted at the next <book>.
while (xml.hasContent()) {
XMLElement book = xml.getNextElement("book");
processBook(book);
}
Does anything like this exist?
© Stack Overflow or respective owner