Xml文档,转义该字符
我有一个 XML 文档,在某些节点中具有段落分隔符,
当我将 XML 加载到 XmlDocument
对象中时,我不再看到该字符。相反,我看到了一个空间。我如何让它显示?
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 category has a paragraph separator
}
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 category has a paragraph separator
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
测试#1:
结果
不会是&
,结果将是"
。所以Contains("& ")
永远不会成立。测试#2:
结果将是两个字节:
x20
和x29
,这正是从 XML 读取的内容。因此字节在那里,你只是看不到它们作为这个 Unicode字符不可读。Test #1:
result
will not be&
, result will be"
. SoContains("&")
will never be true.Test #2:
result will be two bytes:
x20
andx29
, 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.