You can write the document to an OutputStream (which is probably what you want). The tool for this is a Transformer, which you instruct to transform the data from a DOM source to a Stream result.
You first create a TransformerFactory() which give you a transformer.
Then create DOMSource and StreamResult objects and call Transform
Read the documentation in javax.xml.transform