Search code examples
macosunicodensxmlparserline-endings

NSXMLParser converting CRLF to LF


I'm using NSXMLParser to parse XML in a Mac app. The file it's parsing has its line endings set as CRLF (carriage return followed by line feed). I can clearly see the 0D0A in the hex of the text file using Hex Fiend. But when the text comes through the parser to the delegate (via parser:foundCharacters:), that newline shows up as "\n" in the debugger. When I get the binary content of that string by calling dataUsingEncoding, I see that it's just the line feed.

Is there a way to get NSXMLParser to preserve the line endings in the source file?


Solution

  • No, the XML spec requires all parsers to normalise newlines; the original bytes representing a newline are not part of the document's infoset.

    (What's the situation where you need to care?)