How can I generate XML with CR and not CRLF in XmlTextWriter

I am generating XML through XmlTextWriter.

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

But the client provider complains that the line ends are CRLF, not just CR.

Ok, I'm on a Win32 machine using C #, and CRLF is the end of a Win32 line. Is there a way to change the end of lines in an XmlTextWriter?

Also - shouldn't the lines end regardless of the correct XML parser?

see also: What are carriage returns, line feeds, and feeds?

NOTE: it seems that the only answer is a lateral solution - you need to use XmlWriter instead of XmlTextWriter

+3
c # xml newline xmltextwriter
source share
4 answers

of course, after a few minutes, I find the key to MSDN (which I could not find through google), which refers to XmlWriterSettings.NewLineChars

which then led me to an unacceptable answer to SO: Writing an XMLDocument for a file with a specific newline character (C #)

All this in terminology .....

+6
source share

Use XmlWriterSettings to set what you want as the end of the char string.

XmlWriterSettings mySettings = new XmlWriterSettings(); mySettings.NewLineChars = "\r"; XmlWriter writer = XmlWriter.Create( new StreamWriter(@"c:\temp\hello.xml", mySettings); 

I do not know where the end of line characters will be. I have not come across this yet.

+4
source share

Which end of line is used should not matter for a properly implemented analyzer (see specification ), I quote (emphasis mine):

To simplify application tasks, the XML processor should behave as if it normalized all line breaks in the external parsed entities (including the document object) at the input, before parsing, translating the two-character sequence #xD #xA and any #xD followed by do not follow #xA to a single #xA character.

Therefore, you should be fine with the way you have it right now. You may ask what client-client is doing, it is possible that they are doing it wrong.

+1
source share

Use the XmlWriterSettings.NewLineChars property.

0
source share

All Articles