If you only needed to load one section of the document into a DOM tree, you could have implemented a SAX filter, which just passes on certain SAX events and filters out others.
In your case, you can still write a SAX event handler that
* ignores SAX events until it receives the start event for the element whose content is to be loaded into a DOM tree for processing;
* implementing the same kind of API as a SAX filter, you use your SAX handler as a source of SAX events, i.e. you implement the XMLReader interface;
* I recommend you use XOM rather than DOM. The XOM Builder (http://www.xom.nu/apidocs/nu/xom/Builder.html
) can take an XMLReader as its input;
* Each time you come across an element whose content you need to process as a tree, create a new XOM Builder and use your SAX handler as the XMLReader for the Builder. You will have to fake the start/end document events, and pass through the original start element event;
* Your SAX handler will need to track where it is in the original document to match start/end elements. If there is any possible ambiguity (e.g. the element that you are processing can contain other elements with the same name), you can use a stack to track start/end elements, to determine when you are at the end of the block you need to process.
That's a quick overview of what you can do.
Author, XML APIs chapter,
"Advanced XML Applications from the Experts at The XML Guild"