XmlNode Value vs InnerText

后端 未结 5 2047
梦毁少年i
梦毁少年i 2020-12-08 18:03

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

Then I changed i

5条回答
  •  余生分开走
    2020-12-08 18:41

    If, for example, your XML looks like Bar 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).

提交回复
热议问题