How to dump the XML content contains in a org.w3c.dom.Document object to a file.
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File(“C:\\abc.txt”));
transformer.transform(source, result);
The XML content will be saved to abc.txt, and you can also divert the XML content to different output destination by changing the StreamResult constructor, please refer to the API doc for detail.