You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by Willie H Armstrong <wa...@csc.com> on 2004/03/26 04:13:14 UTC

[jdom-interest] XML standard line ending RELATED TO Servlet response's encoding of new lines, what is the correct behavior?




Forgive the long cross-post but the discussion in the JDOM group addresses
why line endings can vary their format.


Willie (Bill) Armstrong
931.788.6256 - Crossville office
860.961.0998 - Cell
warmstr2@csc.com
mmbtoao - AIM
MysticBill - Yahoo Messenger


----------------------------------------------------------------------------------------

This is a PRIVATE message. If you are not the intended recipient, please
delete without copying and kindly advise us by e-mail of the mistake in
delivery. NOTE: Regardless of content, this e-mail shall not operate to
bind CSC to any order or other contract unless pursuant to explicit written
agreement or government initiative expressly permitting the use of e-mail
for such purpose.
----------------------------------------------------------------------------------------


----- Forwarded by Willie H Armstrong/ASD/CSC on 03/25/2004 09:10 PM -----
                                                                                                                                 
                      Rick Beton                                                                                                 
                      <richard.beton           To:      jdom-interest@jdom.org                                                   
                      @dsl.pipex.com>          cc:                                                                               
                      Sent by:                 Subject: [jdom-interest] XML standard line ending                                 
                      jdom-interest-ad                                                                                           
                      min                                                                                                        
                                                                                                                                 
                                                                                                                                 
                      03/11/2004 02:53                                                                                           
                      PM                                                                                                         
                                                                                                                                 
                                                                                                                                 




One thing that puzzles me is org.jdom.output.Format.java:128.  Why is
the standard line ending CR NL?  It would be natural to use the machine
default, i.e. .  The W3C Recommendations (*) specify that some
combination of CR and NL must be used, but they are usually normalised
to a single NL.  It makes sense therefore for line 128 to instead read:

    private static final String STANDARD_LINE_SEPARATOR = "\n";

java.io.PrintWriter uses the system property |line.separator to control
the line endings.  This gives the following option:|
|||
|    private static final String STANDARD_LINE_SEPARATOR =
System.getProperty("line.separator");

This would make XML documents generated by XMLOutputter into normal text
files on whatever system they are created on, which would be generally
useful.

What do folks think?

Rick :-)

(*)
XML1.0: http://www.w3.org/TR/2004/REC-xml-20040204
XML1.1: http://www.w3.org/TR/2004/REC-xml11-20040204/#sec-line-ends
I consulted Format.java rev 1.7

----- Forwarded by Willie H Armstrong/ASD/CSC on 03/25/2004 09:10 PM -----
                                                                                                                                 
                      Elliotte Rusty                                                                                             
                      Harold <elharo           To:      Rick Beton <ri...@dsl.pipex.com>                                 
                      @metalab.unc.edu         cc:      jdom-interest@jdom.org                                                   
                      >                        Subject: Re: [jdom-interest] XML standard line ending                             
                      Sent by:                                                                                                   
                      jdom-interest-ad                                                                                           
                      min                                                                                                        
                                                                                                                                 
                                                                                                                                 
                      03/11/2004 03:46                                                                                           
                      PM                                                                                                         
                                                                                                                                 
                                                                                                                                 




At 8:53 PM +0000 3/11/04, Rick Beton wrote:
>One thing that puzzles me is org.jdom.output.Format.java:128.  Why
>is the standard line ending CR NL?  It would be natural to use the
>machine default, \

No, it would not. It is very damaging to have the same program emit
different output merely because the platform changes. PrintStream is
traditionally problematic for precisely this reason.

The specific choice of \r\n was made because this is the network
standard line ending convention mandated by HTTP among many other
protocols. However, if you want to set something else, you are free
to do so.
--

   Elliotte Rusty Harold
   elharo@metalab.unc.edu
   Effective XML (Addison-Wesley, 2003)
   http://www.cafeconleche.org/books/effectivexml

http://www.amazon.com/exec/obidos/ISBN%3D0321150406/ref%3Dnosim/cafeaulaitA
_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com


----- Forwarded by Willie H Armstrong/ASD/CSC on 03/25/2004 09:10 PM -----
                                                                                                                                 
                      Elliotte Rusty                                                                                             
                      Harold <elharo           To:      Rick Beton <ri...@dsl.pipex.com>                                 
                      @metalab.unc.edu         cc:      jdom-interest@jdom.org                                                   
                      >                        Subject: Re: [jdom-interest] XML standard line ending                             
                      Sent by:                                                                                                   
                      jdom-interest-ad                                                                                           
                      min                                                                                                        
                                                                                                                                 
                                                                                                                                 
                      03/12/2004 05:30                                                                                           
                      AM                                                                                                         
                                                                                                                                 
                                                                                                                                 




At 9:09 AM +0000 3/12/04, Rick Beton wrote:

>That is a matter of opinion not fact; I'm not sure why you consider
>this to be so bad.  The standard Java libraries have taken a
>different position.

Yes, and this has proven by example that this is the wrong way to go.
PrintStream has been a disaster for interoperable network
programming. PrintStream based programs have lots of unexpected bugs
that manifest on only some platforms. I wrote about this extensively
in Java I/O. JDOM should learn from the mistakes in the Java class
library, not repeat them.
--

   Elliotte Rusty Harold
   elharo@metalab.unc.edu
   Effective XML (Addison-Wesley, 2003)
   http://www.cafeconleche.org/books/effectivexml

http://www.amazon.com/exec/obidos/ISBN%3D0321150406/ref%3Dnosim/cafeaulaitA
_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com


----- Forwarded by Willie H Armstrong/ASD/CSC on 03/25/2004 09:10 PM -----
                                                                                                                                 
                      Rick Beton                                                                                                 
                      <richard.beton           To:      jdom-interest@jdom.org                                                   
                      @dsl.pipex.com>          cc:                                                                               
                      Sent by:                 Subject: Re: [jdom-interest] XML standard line ending                             
                      jdom-interest-ad                                                                                           
                      min                                                                                                        
                                                                                                                                 
                                                                                                                                 
                      03/12/2004 03:09                                                                                           
                      AM                                                                                                         
                                                                                                                                 
                                                                                                                                 




Elliotte Rusty Harold wrote:

> At 8:53 PM +0000 3/11/04, Rick Beton wrote:
>
>> One thing that puzzles me is org.jdom.output.Format.java:128.  Why is
>> the standard line ending CR NL?  It would be natural to use the
>> machine default, \
>
>
> No, it would not. It is very damaging to have the same program emit
> different output merely because the platform changes. PrintStream is
> traditionally problematic for precisely this reason.


That is a matter of opinion not fact; I'm not sure why you consider this
to be so bad.  The standard Java libraries have taken a different
position.  In an ideal world, Max PC and Unix line endings would all be
the same.  We don't have that luxury, alas.

> The specific choice of \r\n was made because this is the network
> standard line ending convention mandated by HTTP among many other
> protocols. However, if you want to set something else, you are free to
> do so.


Yes, it is clearly documented:

http://www.jdom.org/docs/apidocs/org/jdom/output/Format.html#setLineSeparator(java.lang.String)


My choice would be to make the JDOM default the same as the system
default, and provide a public static final String with the value "\r\n"
for documents to be sent by HTTP.

Rick :-)