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:
> meselfo wrote:
> > 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
|