L
lard
I'm serializing an XML doc from a DOM representation, using the usual
identity/null transformation method. I'm setting the output encoding
and enabling indent (indent="yes") on the output; in the resulting XML,
the output encoding is coming out as desired, but there are no indents
- all lines of XML are flush left with no spaces in front.
In other words, I'm expecting to see:
<A>
<B>stuff</B>
<C>other stuff</C>
</A>
but instead just get the unindented text as follows:
<A>
<B>stuff</B>
<C>other stuff</C>
</A>
The method that does the serialization is as follows:
public static void writeXML(Node node, OutputStream out) {
TransformerFactory factory = TransformerFactory.newInstance();
Transformer identityTransformer = factory.newTransformer();
Properties outputProps = new Properties();
outputProps.setProperty("encoding", "ISO-8859-1");
outputProps.setProperty("indent", "yes");
identityTransformer.setOutputProperties(outputProps);
DOMSource domSource = new DOMSource(node);
StreamResult streamResult = new StreamResult(out);
identityTransformer.transform(domSource, streamResult);
(Sorry, I don't have a compilable self contained example yet.)
The code which calls the above method is as follows:
ByteArrayOutputStream byteArrayOutStream = new
ByteArrayOutputStream();
// domResult is a DOMResult instance
writeXML(domResult.getNode(), byteArrayOutStream);
// out is a ServletOutputStream
PrintWriter printWriter = new PrintWriter(out);
String resultXmlContent = byteArrayOutStream.toString();
printWriter.print(resultXmlContent);
printWriter.close();
// now we do other things with the resultXmlContent (log to
file)...
So does anyone have an ideas why does the indent="yes" directive appear
to be being ignored?
thanks
Alex
identity/null transformation method. I'm setting the output encoding
and enabling indent (indent="yes") on the output; in the resulting XML,
the output encoding is coming out as desired, but there are no indents
- all lines of XML are flush left with no spaces in front.
In other words, I'm expecting to see:
<A>
<B>stuff</B>
<C>other stuff</C>
</A>
but instead just get the unindented text as follows:
<A>
<B>stuff</B>
<C>other stuff</C>
</A>
The method that does the serialization is as follows:
public static void writeXML(Node node, OutputStream out) {
TransformerFactory factory = TransformerFactory.newInstance();
Transformer identityTransformer = factory.newTransformer();
Properties outputProps = new Properties();
outputProps.setProperty("encoding", "ISO-8859-1");
outputProps.setProperty("indent", "yes");
identityTransformer.setOutputProperties(outputProps);
DOMSource domSource = new DOMSource(node);
StreamResult streamResult = new StreamResult(out);
identityTransformer.transform(domSource, streamResult);
(Sorry, I don't have a compilable self contained example yet.)
The code which calls the above method is as follows:
ByteArrayOutputStream byteArrayOutStream = new
ByteArrayOutputStream();
// domResult is a DOMResult instance
writeXML(domResult.getNode(), byteArrayOutStream);
// out is a ServletOutputStream
PrintWriter printWriter = new PrintWriter(out);
String resultXmlContent = byteArrayOutStream.toString();
printWriter.print(resultXmlContent);
printWriter.close();
// now we do other things with the resultXmlContent (log to
file)...
So does anyone have an ideas why does the indent="yes" directive appear
to be being ignored?
thanks
Alex