The approach would be to build the DOM yourself. When the startElement method is called you would create an Element node and add it as the last child of the current Element (or make it the root if there is nothing yet), then change that node to be the current Element. When the endElement method is called you would change the current Element back to the parent of the current Element. And when the characters() method is called you would make a Text node and add it as the last child of the current Element. I have left out attribute processing and other things like comments, and
you should watch out for namespaces.
I am not going to produce anything more "working" than that because I don't see the point. If you could produce a DOM directly via a DocumentBuilder then why on
earth would you write all that code to do it via SAX? One of the main reasons for using SAX is that you don't have to build the entire DOM in memory; if you do need the DOM then use a DocumentBuilder to construct it.