Wed, 23 Jan 2008 11:10:44 -0500, /Brian Minchau/:
The Xalan
serializer doesn't know about whether the serialized XML will
be used in the the future as an external general parsed
entity and included in yet another XML file.
[...]
There is no Xalan specific option to control this behavior.
I see. Still I think it would be nice if the user could explicitly
control this behavior. As a workaround I've made it output the XML
declaration and a new line manually:
SAXTransformerFactory stf = (SAXTransformerFactory)
TransformerFactory.newInstance();
TransformerHandler handler = stf.newTransformerHandler();
Transformer transformer = handler.getTransformer();
...
transformer.setOutputProperty(OutputKeys
.OMIT_XML_DECLARATION, "yes");
...
OutputStream out = ...;
handler.setResult(new StreamResult(out));
String xmlDecl =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ System.getProperty("line.separator");
out.write(xmlDecl.getBytes("US-ASCII"));
handler.startDocument();
...
--
Stanimir