I wonder if there is really no way to
pretty print a DOM, using Java's
standard API (http://java.sun.com/j2se/1.4.2/docs/api/index.html).
What I've tried is (assume having a org.w3c.dom.Document instance doc:
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty("encoding", encoding);
transformer.setOutputProperty(OutputKeys.INDENT,"yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "3" );
DOMSource source = new DOMSource(doc);
FileOutputStream os = new FileOutputStream(file);
StreamResult result = new StreamResult(os);
transformer.transform(source,result);
which gives, e.g. something like
<?xml version="1.0" encoding="ISO-8859-1"?>
<documentData>
<Asset assetID="229609"/>
<Picturedescription>
<Asset assetID="229609"/>
</Picturedescription>
</documentData>
which is not even proper indent. I can't believe that there is no way in pretty prenting an XML document, using Java's Standard API....
Does anybody know more about it?
Urs