I am attempting to figure out why some text apparently doesn't have any carriage returns in it, even though it looks like it does. I am wondering if calling innerText when Xpath'ing through a XmlDocument (in .net 4.0) strips carriage returns or other characters. Probably not, But at this point I looking for anything.
InnerText when using XMLDocument removing carriage returns?
1.5k Views Asked by SoftwareSavant At
2
There are 2 best solutions below
0

What's the xml:space
on the element? If you need to force it to be preserve whitespace other than significant whitespace, then you can set PreserveWhitespace
to true
before calling Load
or LoadXML
.
Be cautions with this though as in most cases the person writing the XML will expect the normal XML rules for whitespace to be followed. Even worse, if you get a "works for me" by using the non-standard rules that PreserveWhitespace
uses, there's no reason you should expect anyone else to parse it as you intend.
You haven't shown any code, so it's hard to know where the data came from. By default, insignificant whitespace is not preserved when loading an
XmlDocument
. You might want to try settingXmlDocument.PreserveWhitespace
to true before loading.If that doesn't help, please post a short but complete program which demonstrates the problem.