Constructing DOM using StAX Writers
By venu on Feb 10, 2006
I recently added support for createXMLStreamWriter(DOMResult result) method in SJSXP. It is of great use where implementations spit out XML documents to a StreamWriter and you want to construct a DOM tree instead of dumping it to the OuputStream. Following code snippet shows how to create a StAX writer that builds a Document.
XMLOutputFactory xof = XMLOutputFactory.newInstance();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
XMLStreamWriter writer = xof.createXMLStreamWriter(new DOMResult(doc));