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
  • 115,751
  • 26
  • 228
  • 437
minerals
  • 6,090
  • 17
  • 62
  • 107

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
  • 842,883
  • 184
  • 1,785
  • 1,677