all groups > dotnet xml > august 2004 >
You're in the

dotnet xml

group:

xmlNode.InnerText vs. xmlNode.Value


xmlNode.InnerText vs. xmlNode.Value Dan
8/27/2004 4:41:44 PM
dotnet xml:
I've loaded the following xml into an XMLDocument object:

<?xml version="1.0" ?>
- <Preferences>
<Institution>Argh</Institution>
<Speaker>Chigier, Ben (1234)</Speaker>
<Worktype>Addendum</Worktype>
<speakerCode>1234</speakerCode>
</Preferences>

I then try to retrieve the value of the Institution node as follows:

string s = myxmldoc.SelectSingleNode("/Preferences/Institution").Value;

However, s is null after the call. But if I change the call to the
following, s is what I'd expect: "Argh".

string s = myxmldoc.SelectSingleNode("/Preferences/Institution").InnerText;

Anyone know what's going on?

Thanks...

Dan

Re: xmlNode.InnerText vs. xmlNode.Value Derek Harmon
8/27/2004 10:13:37 PM
[quoted text, click to view]

InnerText goes through the descendant XmlText node(s) of an
XmlNode, and concatenates their value(s) together. It is the
Value property of the XmlText node(s) that contains text.

There are some questions to ask yourself about XmlElement,
and what the representation of it's Value should be:

If it had a value, what would it be? LocalName?
NamespaceURI? QName? InnerText? InnerXml?
Does an Element whose InnerXml is "<b>Hey</b>"
have a Value different from one whose InnerXml is
"Hey," and should it be different?

The Value property of an XmlElement is always null because
XmlElements have no representable value.


Derek Harmon

Re: xmlNode.InnerText vs. xmlNode.Value Martin Honnen
8/28/2004 2:29:16 PM


[quoted text, click to view]

Well simply what you expect to be the value of an element is not the
Value property in the DOM (document object model) that .NET implements.
In that model there is a base class XmlNode which already has the Value
property and in its documentation at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXmlNodeClassValueTopic.asp
details are given what the Value is for the different type of nodes. For
Element nodes it says
"A null reference (Nothing). You can use the XmlElement.InnerText or
XmlElement.InnerXml properties to access the value of the element node."

--

Martin Honnen
Re: xmlNode.InnerText vs. xmlNode.Value Jediah L.
8/28/2004 9:26:28 PM
It all depends on your NodeType.

This out outlined in the following MSDN article:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemxmlxmlnodeclassvaluetopic.asp


If you are going after the Text in a node (type Element or type Text) your
best bet is to use .InnerText



[quoted text, click to view]

AddThis Social Bookmark Button