Subjects
Home
Xalan extension functions
Fomatting question serializing DOM with pretty print
xalan with pull parser
Cannot find the declaration
Apache Xalan drop support to run on JRE 1 1 x
Why does Doctype change processing of a document
Node set to XML string via Java extensions in Xalan J: possible?
Templates/Transformers + thread safety???
Problem evaluating xpath with muliple prefix with different namespace
remove an arbitrary attribute from xsl output
Xalan3 XSLT 2 0 XPath 2 0 support?
Problem using compiled translets with Xalan !!
Xalan and jstl 1 1 problem with transform tag
NullPointer in DOM2DTM getLocalName
URIResolvers base parameter with xsltc and cascaded imports
Performance problem for Xalan J on intel dual core
Standard libraries in JAXP?
Serializing a DOM tree to XML file, customize entities replacement
Library Conflict Involving BCEL Library
A question on how users are using <xsl:message >
Kevin Cormier as a new Apache Xalan J committer
Struggling to iterate over tokenized string
Xalan count() trouble
Problem with recursive xpath
Error when switching to java 1 5
document( ' ')
Problem with Xalan2 7 0 transformation
cr/lf options
entity encoded XML
can xalan transform 2 xml using one xslt?
Xalan J JIRA defect review Monday October 16, 2006 from 2:00 to 3:30 pm ED
xsl transform with cdata section elements
xslt parameters not expanded
Weird behavior of XPath evaluate()
How to avoid <xsl:message > instruction prints stylesheet file informations ?
Cannot find SimpleTransform subdirectory after installing Xalan J
recover from document not found exceptions
jdk1 5 and Xalan jar differences?
Performance Issue
Error/Bug adding floating point numbers
XPathAPI: eval exp using nodes with default namespace
modifying xalan to output invalid XML
NullPointerException
mege two separate xml nodes into one
Is this a XALAN document identification bug?
is StylesheetRoot really java io Serializable ?
transform() fails for DOMSource but succeeds for StreamSource
Thoughts on Transformer parameter passing
HELP, Xalan and jstl 1 1 problem with transformer
Problem with XPath namespace axis?
string utils:replace deleting search string if replacement string is an HTML
help with enumeration values pls
xalan 2 5 1 vs 2 7 performance question
How to insert/update in XML document
HTML Serialization and Handling of Ampersands in HREF Attributes
XHTML link tag stripping
SystemId Unknown; Line #24; Column #49; java lang NullPointerException
xpath text() help
Apostrophe problem with xalan 2 7 0
How to set variables in XML document?
Links
Home
Oracle database error code ...
 
Search:  
Power your search with and, or, +, -, or "some phrase" operators.
Fomatting question serializing DOM with pretty-print

Fomatting question serializing DOM with pretty-print

2007-02-20       - By Dick Deneer
Reply:     1     2     3     4     5     6     7     8     9     10     >>  


Brian,

Thanks for the explanation.
As already commented in the example test code, it is possible to filter out
whitespace in the calling program.
To workaround the issue with the indent (newline) of the root may be more
complicated.
I hope that in the future the xalan parser will bring full backwards
compatibility with the deprecated xerces one.

Dick Deneer



Brian Minchau wrote:
>
> Hi Dick,
> I ran the program that you point to with the URL and got your results.
>
> For this input:
> String xml = "<root>\n\n\n<child1>text</child1>
> <child2>text</child2></root>";
>
> For Xalan serializer and then Xerces serializer I get this:
>
> Program started
> Xalan serializer will be used
> <?xml version="1.0" encoding="UTF-16"?><root>
>    <child1>text</child1>
>    <child2>text</child2>
> </root>
>
>
> Program started
> Xerces serializer will be used
> <?xml version="1.0" encoding="UTF-16"?>
> <root>
>     <child1>text</child1>
>     <child2>text</child2>
> </root>
>
>
> The differences here are due to the fact that in the past the Xalan
> serializer has decided that the output XML file could be used as an
> external general parsed entity and included in yet another XML file.  As
> such we don't know where it will be included and the extra newline that
> Xerces inserts after the XML header may be included next to non-whitespace
> text and become part of that text node.  Added indentation or not, extra
> whitespace before the document element is not always correct, so Xalan
> doesn't do it.
>
> I looked at the code recently and saw that the DOM3 save support does
> indeed choose to indent 3 spaces per indentation level, and this code was
> contributed by to Xalan by people on the Xerces team, so I don't know why
> Xerces indents by 4 spaces.  This difference is not important, there is no
> "right" way to do indentation, it depends on implementation.
>
>
>
> Then to add some whitespace, for this input:
> String xml = "<root>\n\n\n<child1>text</child1>
> <child2>text</child2></root>";
>
> Program started
> Xalan serializer will be used
> <?xml version="1.0" encoding="UTF-16"?><root>
>
>
> <child1>text</child1> <child2>text</child2>
> </root>
>
>
>
>
> Program started
> Xerces serializer will be used
> <?xml version="1.0" encoding="UTF-16"?>
> <root>
>     <child1>text</child1>
>     <child2>text</child2>
> </root>
>
>
> Again Xalan does not inject any whitespace between the xml header and the
> document element, for the same reasons as given before.  I'm not sure
> about
> the other whitespace differences. It looks like Xalan has decided that it
> won't add whitespace to existing whitespace and effectively does no
> indentation.  Xerces serializer however rips out the whitespace from the
> document being serialized and replaces it with nicer looking whitespace.
> I'm not sure if that is OK to do that, perhaps someone from Xerces will
> comment on the differences.
> (Michael?)
>
>
> - Brian
> - - - - - - - - - - - - - - - - - - - -
> Brian Minchau, Ph.D.
> XSLT Development, IBM Toronto
> e-mail:        minchau@(protected)
>
>
>
>                                                                            
>              Dick Deneer                                                  
>              <dick.deneer@(protected)                                            
>              eydevelopment.com                                          To
>              >                         xalan-j-users@(protected)        
>                                                                         cc
>              02/19/2007 07:40                                              
>              AM                                                    Subject
>                                        Fomatting question serializing DOM  
>                                        with pretty-print                  
>                                                                            
>                                                                            
>                                                                            
>                                                                            
>                                                                            
>                                                                            
>
>
>
>
>
> I build a DOM with the following xml :
> <root><child1>text</child1><child2>text</child2></root>
> After serializing using the xalan serializer with the pretty-print option
> I
> get:
> <?xml version="1.0" encoding="UTF-16"?><root>
>    <child1>text</child1>
>    <child2>text</child2>
> </root>
>
> So the opening of the root is also in the first line.
>
> Second when I put in carriage returns or spaces, this effects the
> formatting
> seriously.
> For instance when I build a DOM with:
> <root>\n\n\n<child1>text</child1> <child2>text</child2></root>
> After serializing I get:
> <?xml version="1.0" encoding="UTF-16"?><root>
>
>
> <child1>text</child1> <child2>text</child2>
> </root>
>
> In all the cases the xerces serializer returns:
> <?xml version="1.0" encoding="UTF-16"?>
> <root>
>     <child1>text</child1>
>     <child2>text</child2>
> </root>
>
> Can you tell me if this behaviour i right?
> http://www.nabble.com/file/6633/TestSerializer.java TestSerializer.java
> --
> View this message in context:
> http://www.nabble.com/Fomatting-question-serializing-DOM-with-pretty-print
-tf3252607.html#a9041632
>
> Sent from the Xalan - J - Users mailing list archive at Nabble.com.
>
>
>
>
>

--
View this message in context: http://www.nabble.com/Fomatting-question
-serializing-DOM-with-pretty-print-tf3252607.html#a9067789
Sent from the Xalan - J - Users mailing list archive at Nabble.com.