Reputation: 48558
I am creating an XML File where a tag's Innertext is \r\n
It is creating fine. But when i read these xml files in code-behind \r\n
gets read as \n\n
I am reading it through XMLTextReader
.
What could be the reason for this and how to read it like it was provided?
Upvotes: 1
Views: 1482
Reputation: 498904
You need to encode such characters in order for them to be preserved.
One approach is to replace the characters with the respective character reference:
\n
to
\r
to
Another one would be to enclose sections that need to preserve whitespace in <![CDATA[]]>
sections.
Upvotes: 2
Reputation: 965
The question doesn't provide enough details to correctly answer it. So I will be assuming things here.
A few things should be considered:
These points can be of influence to your problem. But when re-reading your question, I think it is the CDATA solution you are looking for to keep your innertext from being misinterpreted by an XML parser.
My guess is to wrap the \r\n
innertext in a CDATA tag.
More info on a CDATA tag can be found here: CDATA
Good luck!
Upvotes: 0