.NET: XmlElement - difference between Value, InnerText, and InnerXml(转)
时间:2010-10-15 来源:酱板猪
<aNode anAttribute="Hello"> Some Big <b>Bad</b> text </aNode>
This will give:
Value: null InnerText = "Some Big Bad text" InnerXml = "Some Big <b>Bad</b> text" OuterXml = "<aNode anAttribute="Hello">"Some Big <b>Bad</b> text"</aNode>
All of the above makes sense enough -- the only one that always left me a little bit wanting was the Value property that XmlElement inherits from XmlNode -- I invariably code sing that property, and then, realizing my mistake on first run, correct it to point to InnerText.
The nagging question, really, for me, was why is it null? Doesn't make much sense to me.
I don't have an answer to it, but I did find this table today on the definition of XmlNode.Value:
The value returned by Value depends on the NodeType of the node:
- CDATASection: the content of the CDATA Section.
- Comment: the content of the comment.
- Document: null.
- DocumentFragment: null.
- DocumentType: null.
- Element: null. Use the XmlElement.InnerText or XmlElement.InnerXml properties to access the value of the element node.
- Entity: null.
- EntityReference: null.
- Notation: null.
- ProcessingInstruction: the entire content excluding the target.
- Text: the content of the text node.
- SignificantWhitespace: the white space characters (can consist of one or more space, carriage return, line feed, or tab chars).
- Whitespace: the white space characters (can consist of one or more space, carriage return, line feed, or tab chars).
- XmlDeclaration: the content of the declaration (that is, everything between <?xml and ?>).
相关阅读 更多 +