Search code examples
c#xmlnewlinexmltextwriter

How can I generate XML with CR, instead of CRLF in XmlTextWriter


I'm generating XML via XmlTextWriter.

The file looks good to my eyes, validates (at wc3), and was accepted by the client.

But a client vendor is complaining that the line-endings are CRLF, instead of just CR.

Well, I'm on a Win32 machine using C#, and CRLF is the Win32 standard line-ending. Is there any way to change the line-endings in the XmlTextWriter?

Also -- shouldn't the line-endings not matter to a proper XML parser?

see also: What are carriage return, linefeed, and form feed?

NOTE: looks like the only answer is a sideways solution -- you have to use the XmlWriter instead of the XmlTextWriter


Solution

  • of course, moments after asking, I find a clue on MSDN (that I couldn't find via google) that refers to XmlWriterSettings.NewLineChars

    which then led me to the unaccepted answer on SO: Writing XMLDocument to file with specific newline character (c#)

    It's all in the terminology.....