开发者

Xml Document, escape this character

I have an XML document that has the paragraph separator character in some nodes as 


When I load XML into an XmlDocument object, I no longer see this character. Instead I see a space. How do I get it to show 
?


XmlDocument doc = new XmlDocument();
doc.Load(xmlFilePath); 
XmlNodeList nodes = doc.SelectNodes("/catalog/classes"); 
foreach(XmlNode node in nodes) { 
    string category = node["category"]; 
    bool containerSeperator = category.Contains("
") // this should return true but it returns false. This ca开发者_运维知识库tegory has a paragraph separator
}


Test #1:

var xmlText = @"<Test>&amp;</Test>";
var xml = XDocument.Parse(xmlText);
var result = xml.Element("Test").Value;

result will not be &amp;, result will be ". So Contains("&amp;") will never be true.

Test #2:

var xmlText = @"<Test>&#x2029;</Test>";
var xml = XDocument.Parse(xmlText);
var result = Encoding.Unicode.GetBytes(xml.Element("Test").Value);

result will be two bytes: x20 and x29, which is exactly what is read from XML. So the bytes are there you just don't see them as this Unicode character is not readable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜