2

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?

jonrsharpe
  • 107,083
  • 22
  • 201
  • 376
minerals
  • 5,609
  • 15
  • 58
  • 100

1 Answers1

2

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

Community
  • 1
  • 1
unutbu
  • 777,569
  • 165
  • 1,697
  • 1,613