有关XmlElement.InnerText和空白问题 [英] Question about XmlElement.InnerText and whitespace

查看:546
本文介绍了有关XmlElement.InnerText和空白问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的XML元素:

I have an XML element that looks something like this:

<content locale="en"> </content>

之间的括号内的东西文本由单个空格字符。当我加载XML到XmlDocument看一下上述元素的XmlElement对象,我希望:

The text between the bracketed stuff consists of a single space character. When I load the XML into an XmlDocument look at the XmlElement object for the above element, I expect:

contentElement.InnerText.Length == 1; // InnerText should be a single space character

而是我所得到的是

but instead what I get is

contentElement.InnerText.Length == 0;

假设这不是微软的DOM实现中的错误,这是在XML / DOM规范,我不知道的功能?如果是这样,我有什么选择,但添加转义空格字符当XML写出来的?

Assuming this is not a bug in Microsoft's DOM implementation, is this a feature of the XML/DOM specification I'm not aware of? If so, do I have any options but to add escaped whitespace characters when the XML is written out?

推荐答案

如果您希望您的XML文件里pserved空格$ P $进行解析,请考虑使用后的&LT;![CDATA [ ]]&GT; 部分,让解析器知道它应该借此字符数据从字面上...

If you want to have whitespace preserved inside of your XML file after being parsed please consider using <![CDATA[ and ]]> section to let parser know that it should take this character data literally...

这篇关于有关XmlElement.InnerText和空白问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆