XML formatting LF/CR?

M

meselfo

I cant get the java api to use linefeed and carriage return in the xml
that im producing:

StreamResult result = new StreamResult(output);
DOMSource source = new DOMSource(doc);
Transformer transformer =
TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.transform(source, result);

The xml produced is a single line.
What is needed to "pretty print" the xml?
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

meselfo said:
I cant get the java api to use linefeed and carriage return in the xml
that im producing:

StreamResult result = new StreamResult(output);
DOMSource source = new DOMSource(doc);
Transformer transformer =
TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.transform(source, result);

The xml produced is a single line.
What is needed to "pretty print" the xml?

There are several ways of outputting an
org.w3c.dom.Document nicely.

But you can also do it in the XSLT transformation by
putting:

<xsl:text>
</xsl:text>

in the XSL source.

Arne
 
M

meselfo

Do you mean like this?:

StringReader sr = new StringReader("<xsl:text></xsl:text>");
javax.xml.transform.Source xsltSource =
new javax.xml.transform.stream.StreamSource(sr);
ByteArrayOutputStream output = new ByteArrayOutputStream();
StreamResult result = new StreamResult(output);
DOMSource source = new DOMSource(doc);
TransformerFactory fac = TransformerFactory.newInstance();
Transformer transformer = fac.newTransformer(xsltSource);
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.transform(source, result);

It still results in single line xml.

Btw. im using sun jdk 1.5.0_10


Arne Vajhøj skrev:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top