File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes How to preserve space when parsing XML with Xalan Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to preserve space when parsing XML with Xalan" Watch "How to preserve space when parsing XML with Xalan" New topic
Author

How to preserve space when parsing XML with Xalan

Joe Simone
Greenhorn

Joined: Feb 16, 2005
Posts: 25
I have XML that looks like

and I would like to preserve the new-line characters. But when I parse, the text all wraps together and the newlines are lost. What can I do?

Here is the parsing code:


Many thanks for any insight.
Joe
Joe Simone
Greenhorn

Joined: Feb 16, 2005
Posts: 25
Oops, the newlines did not show on the post. Each line of the query tag ends with (and pound x d semicolon).

So the XML does have newlines in it.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Actually, 
 is a carriage-return character. The new-line character is 
. Check out section 2.11 of the XML Recommendation to see what is happening.
Joe Simone
Greenhorn

Joined: Feb 16, 2005
Posts: 25
Ok.

I added the following code to the createDocumentFromString method


and now I only have 
 where the 
 used to be but the results
are the same. Xalan is losing the fact that newlines are specified. How can I get Xalan to respect the 
 ?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to preserve space when parsing XML with Xalan
 
Similar Threads
Throws IllegalArguementException when validating XML with schema
XML Parsing and Validation with SAX parser shoots CPU to 100% utilization
Validate XML from a string instead of a file?
Loading a schema that refers to another one.
location of xsd file