Newbie: CR/LF and tabs

T

Thorsten Kettner

Hi all,
I've been told to write an xml file and I wonder if I can use CR/LF
and tabs in the data (like in html's <pre></pre>).

<?xml version="1.0" encoding="ISO-8859-15"?>
<MYDATA>
<MYLIST>Line 1
Line 2
Line 3</MYLIST>
</MYDATA>

Will the parser correctly return a string containing two linefeeds?

Or should I use cr identifiers (like \n in Line1\nLine2\nLine3) and
manually split the line that the parser gives me?

I know this is a common question, sorry, but searching Google groups I
didn't find the answer due to being a beginner and due to the fact
that most questions target a certain parser, not xml in general.
 
S

Steve W. Jackson

:Hi all,
:I've been told to write an xml file and I wonder if I can use CR/LF
:and tabs in the data (like in html's <pre></pre>).
:
:<?xml version="1.0" encoding="ISO-8859-15"?>
:<MYDATA>
: <MYLIST>Line 1
:Line 2
:Line 3</MYLIST>
:</MYDATA>
:
:Will the parser correctly return a string containing two linefeeds?
:
:Or should I use cr identifiers (like \n in Line1\nLine2\nLine3) and
:manually split the line that the parser gives me?
:
:I know this is a common question, sorry, but searching Google groups I
:didn't find the answer due to being a beginner and due to the fact
:that most questions target a certain parser, not xml in general.

Keeping in mind that end of line marks are platform specific (that is,
only Windows uses CR/LF), it's doubtful that any good parser would
maintain those line breaks. If there's an encoded character that
represents EOL and will be respected by a parser, I am not aware of it.

In my experience, the lines you create will get written that way, but
they'll be lost when you read the document the next time. Our app
includes an editor for our own needs, and we decided that the only
effective way to handle this was to put each "line" into its own element
or attribute. It's more work to handle it when writing/reading, but it
guaranteed the results.

= Steve =
 
J

Julian F. Reschke

I think this is completely wrong.

The only normalization the XML parser is allowed to do here is line end
normalization (and that shouldn't be an issue at all).

If this would be a problem, the <pre> element in XHTML wouldn't work. But it
does.

Julian
 
D

Dimitre Novatchev

Keeping in mind that end of line marks are platform specific (that is,
only Windows uses CR/LF), it's doubtful that any good parser would
maintain those line breaks. If there's an encoded character that
represents EOL and will be respected by a parser, I am not aware of it.

On the contrary -- any conformant parser must normalize any combination of
CR and NL to a single NL (
)


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
 
T

Thorsten Kettner

Hi all,
I've been told to write an xml file and I wonder if I can use CR/LF
and tabs in the data (like in html's <pre></pre>).
[snip]

Thank you very much Steve, Julian and Dimitre for your answers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top