Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > XML formatting LF/CR?

Reply
Thread Tools

XML formatting LF/CR?

 
 
meselfo
Guest
Posts: n/a
 
      01-09-2007
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?

 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
Guest
Posts: n/a
 
      01-10-2007
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
 
Reply With Quote
 
 
 
 
meselfo
Guest
Posts: n/a
 
      01-10-2007
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting XML with an XSLT without access to the XML cp XML 2 08-20-2007 06:50 PM
XSLT xml to xml simple question about formatting kbozek@yahoo.com XML 1 06-07-2007 10:48 PM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
Need formatting options menu for formatting hard drive Mark T. Computer Support 3 11-24-2003 11:50 PM
XML Formatting/Sorting Utility Mark Lookabaugh XML 1 07-17-2003 06:00 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57