[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] How does XML handle differing line break characters on different platfor
[This is an expanded version of the summary that I sent out a few minutes ago. I thought that some people might find this a bit less terse and more understandable (plus I elaborated on some things).] 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"?> \n\r <Test> \n\r <para xml:space="preserve">This is a \n\r simple paragraph. What \n\r do you think of it?</para> \n\r </Test> \n\r 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 entity reference: 
 /Roger
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|