tags:

views:

607

answers:

2

Hey guys, is there any way to tell the Transformer (when serializing an xml document using DOM), to omit the standalone attribute?

Preferably without using a hack , i.e. ommitting the whole xml declaration and then prepending it manually.

Thanks

-Vic

My current code:

Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.STANDALONE, "yes"); //Note nothing is changed

StreamResult result = new StreamResult(new StringWriter());
DOMSource source = new DOMSource(document);
transformer.transform(source, result);
 return result.getWriter().toString();

Current:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<someElement/>

Intended:

<?xml version="1.0" encoding="UTF-8">
<someElement/>
+3  A: 

Figured it out..

Instead of changes to the transformer,

I add the following to the document object.

  document.setXmlStandalone(true);
vicjugador
A: 

Which Java version are you using and/or which XSLT transformer? With Sun Java 1.6.0_16, the standalone attribute is only set in the output document if you set the output property and the content is also correct.

jarnbjo