[Updated] How does XML handle differing line break characters on differe
[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:
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