[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

[Updated] How does XML handle differing line break characters on differe

  • To: xml-dev@l...
  • Subject: [Updated] How does XML handle differing line break characters on different platforms? Read this to find out.
  • From: "Roger L. Costello" <costello@m...>
  • Date: Mon, 08 Sep 2003 15:04:51 -0400
  • Organization: The MITRE Corporation

line break in xml
[Thanks David and Amelia for identifying the typos in my summary.  I
believe that this summary has fixed them.]

Hi Folks,

Different systems use different line break characters.  How do you
handle this in XML?  Read on and find out.

Consider this XML document: (line break characters are explicitly shown)

<?xml version="1.0"?> \r\n
<Test> \r\n
     <para xml:space="preserve">This is a \r\n
     simple paragraph. What \r\n
     do you think of it?</para> \r\n
</Test> \r\n

When an XML parser reads in this document it "normalizes" ALL line
breaks.  Thus, after normalization the XML document looks like this:

<?xml version="1.0"?> \n
<Test> \n
     <para xml:space="preserve">This is a \n
     simple paragraph. What \n
     do you think of it?</para> \n
</Test> \n

Things to note:

1. All line breaks have been normalized to \n.

Consequence: you don't have to be concerned about different platforms
using different line break characters since all XML documents will have
their line break characters normalized to \n regardless of the
platform.  (So, if you're writing an XML Schema regex expression you can

simply use \n to indicate line break, regardless of the platform.)

2. The xml:space="preserve" attribute has no impact on line break
normalization.

3. Suppose that you want a line break character in your XML document,
other than \n. For example, suppose that you want \r in your XML
document.  By default, it would get normalized to \n.  To prevent this,
use a character reference: &#xD;

/Roger



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.