Innertext使用XMLDocument去除回车率吗?
题
我试图弄清楚为什么一些文本显然没有任何回程,即使它看起来也是如此。我想知道在XPathing通过XMLDocument(在.NET 4.0中)带回车返回或其他字符时调用InnerText。可能不是,但此时我正在寻找任何东西。
解决方案
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 setting XmlDocument.PreserveWhitespace
to true before loading.
If that doesn't help, please post a short but complete program which demonstrates the problem.
其他提示
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.