Parsing XML with SAX and DOM chunking (part 1)

I was looking for a means of parsing a large XML document while retaining the ability to process particular elements of interest. In this post I will demostrate a way of parsing an XML document with a SAX XMLReader and use an XMLFilter implementation that watches for element(s) nominated by name.

The class below performs partial unmarshalling on a DOM node representing a fragment of the overall document. When the start of the element is discovered we start capturing into the DOM Node and when the corresponding element end is discovered the DOM node is unmarshalled using JAXB, the provided listeners are called passing the recognised object to a handler method.

The following parameterised class implements the chunking facility.

In the next part of the series I will demonstrate how to use the class above.

Tagged with: , , , ,
Posted in Java, Sax, Xml

Leave a Reply

Your email address will not be published.