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>&</Test>";
var xml = XDocument.Parse(xmlText);
var result = xml.Element("Test").Value;
result
will not be &
, result will be "
. So Contains("&")
will never be true.
Test #2:
var xmlText = @"<Test>
</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.
精彩评论