XMLNode值,VS的InnerText [英] XmlNode Value vs InnerText

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

问题描述

我创建了学校Ping应用程序使用XML完整URL的了。 我失去了一个小时,因为 XmlNode.Value 是导致空。

然后,我把它改为的InnerText 和它工作得很好。

现在我不知道有什么区别,因为MSDN说.value的返回节点的值,的InnerText 返回节点及其所有子节点的连接值。

有人可以解释这对我好吗?

 <网站>
<网站>
    <网址> www.test.be< / URL>
    &LT;电子邮件&GT; test@test.be< /电子邮件&GT;
&LT; /网站&GT;
&LT;网站&GT;
    &LT;网址&GT; www.temp.be&LT; / URL&GT;
    &LT;电子邮件&GT; temp@temp.be< /电子邮件&GT;
&LT; /网站&GT;
&LT;网站&GT;
    &LT;网址&GT; www.lorim.ipsum&LT; / URL&GT;
    &LT;电子邮件&GT; interim.address@domain.com< /电子邮件&GT;
&LT; /网站&GT;&LT; /网站&GT;
 

解决方案

如果,例如,您的XML看起来像&LT;富&GT;酒吧和LT; /美孚&GT; 然后酒吧竟然被认为是一个单独的节点:一个 XMLTEXT 节点(子类从的XmlNode )。那本属性 XMLTEXT 节点将是酒吧。

foo被认为是的XmlElement (也子类从的XmlNode )。 XmlNode.Value 返回基于节点是类型不同的东西。请参见该表这表明总是返回元素节点。

的InnerText 的富节点返回酒吧,因为它会将其子女的价值观(在这种情况下,只有一个 XMLTEXT 节点)。

I'm creating a ping application for school with an XML full of URL's. I lost an hour because of XmlNode.Value was resulting in a null.

Then I changed it into InnerText and it worked fine.

Now I was wonder what's the difference because MSDN says that .Value returns the value of the node and InnerText returns the concatenated values of the node and all its child nodes.

Can someone explain this for me please?

<sites>
<site>
    <url>www.test.be</url>
    <email>test@test.be</email>
</site>
<site>
    <url>www.temp.be</url>
    <email>temp@temp.be</email>
</site>
<site>
    <url>www.lorim.ipsum</url>
    <email>interim.address@domain.com</email>
</site></sites>

解决方案

If, for example, your XML looks like <Foo>Bar</Foo> then "Bar" is actually considered a separate node: an XmlText node (sub-classed from XmlNode). The Value property of that XmlText node would be "Bar".

"Foo" is considered to be an XmlElement (also sub-classed from XmlNode). XmlNode.Value returns different things based on the type of node it is. See this table which shows that Value always returns null for Element nodes.

The InnerText of the Foo node returns "Bar" because it concatenates the values of its children (in this case, only the one XmlText node).

这篇关于XMLNode值,VS的InnerText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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