tastyminerals
tastyminerals

Reputation: 6538

Why does xml.etree.ElementTree method findtext() convert \r\n to \n?

I have an XML file I use for testing and I test raw string against raw string. My test file contains the following data:

<output>
  first line\r\n
  second line\r\n
</output>

My to-be-tested function returns:

first line\r\n
second line\r\n

However, when I use xml.etree.ElementTree method findtext('output') (which should return text within <output></output> tags) the returned text has line separators replaced:

first line\n
second line\n

I have to replace them back, which is annoying. This behaviour is unexpected. Has anybody run into this issue and how do you handle it?

Upvotes: 3

Views: 820

Answers (1)

unutbu
unutbu

Reputation: 879471

All XML compliant parsers must convert CRLF line endings to LF. So you shouldn't need to write \r\n.

Upvotes: 3

Related Questions