C# XDocument.Parse 保留空格space

一直以來在解析xml或者html的時候,都是直接Xdocument.Parse(string text),然後取Node什麼的;

最近遇到一個問題,解析的xml文章取出之後,英文空格都沒有了,單詞都合併到了一起。

Debug了下發現text在Parse前後,space都沒有了。

於是MSDN查了下XDocument.Parse,遺漏了

LoadOptions.PreserveWhitespace。

Remarks: 

If the source XML is indented, setting the PreserveWhitespace flag in options causes the reader to read all white space in the source XML. Nodes of typeXText are created for both significant and insignificant white space.

If the source XML is indented, not setting the PreserveWhitespace flag in options causes the reader to ignore all of the insignificant white space in the source XML. The XML tree is created without any text nodes for insignificant white space.

If the source XML is not indented, setting the PreserveWhitespace flag in options has no effect. Significant white space is still preserved, and there are no spans of insignificant white space that could cause the creation of more white space text nodes.

LoadOptions另外還有2個屬性:SetBaseUri和SetLineInfo。。。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章