public static void outputXML(Document doc, PrintStream stream) throws XMLHelperException {
try {
OutputFormat of = new OutputFormat(doc);
of.setIndenting(true);
XMLSerializer serializer = new XMLSerializer(stream, of);
serializer.serialize(doc);
} catch (IOException ioe) {
throw new XMLHelperException("Unable to write to the given print stream", ioe);
}
}public static void outputXMLToFile(Document doc, String fileName) throws XMLHelperException {
try {
OutputFormat of = new OutputFormat(doc);
of.setIndenting(true);
File f = new File(fileName);
FileOutputStream fos = new FileOutputStream(f);
XMLSerializer serializer = new XMLSerializer(fos, of);
serializer.serialize(doc);
fos.close();
} catch (IOException ioe) {
throw new XMLHelperException("Unable to write to the given file", ioe);
}
}