473,322 Members | 1,719 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

xmlNode.InnerText vs. xmlNode.Value

Dan
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
Nov 16 '05 #1
3 19569
"Dan" <da*@dontspamme.com> wrote in message news:ep**************@TK2MSFTNGP15.phx.gbl...
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?


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
Nov 16 '05 #2


Dan wrote:
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?


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/de...ValueTopic.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
http://JavaScript.FAQTs.com/
Nov 16 '05 #3
It all depends on your NodeType.

This out outlined in the following MSDN article:

http://msdn.microsoft.com/library/de...valuetopic.asp
If you are going after the Text in a node (type Element or type Text) your
best bet is to use .InnerText

"Dan" <da*@dontspamme.com> wrote in message
news:ep**************@TK2MSFTNGP15.phx.gbl...
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

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dan | last post by:
I've loaded the following xml into an XMLDocument object: <?xml version="1.0" ?> - <Preferences> <Institution>Argh</Institution> <Speaker>Chigier, Ben (1234)</Speaker>...
2
by: Josema | last post by:
Hi, Im trying to get a xmlnode having the value of an attribute, but without success this is my xml file: <promotions> <promotion id="0"> <image>images/gifs/Panel4/Panel4_Prom2.gif</image>...
4
by: David Dvali | last post by:
Hello. I have such XML file: <root> <elem1> <optional> Some data <optional> </elem1> </root>
1
by: PaulF | last post by:
I am writing a web service that accepts and returns an XML message - I know the issues behind this but want to be able to process the messages generically using XSD / XSLT. My problem occurs...
3
by: Earl | last post by:
In VB.Net, the following declaration builds and executes with no exceptions: Dim XMLDoc As New XmlDocument Dim Node As XmlNode But in C#, the following (equivalent?!) returns the build error...
2
by: =?iso-8859-1?Q?Norbert_P=FCrringer?= | last post by:
Hello! Is it possible to use the object XMLNode as a parameter in an interface function of a WCF service? In my case I get the error message: XmlNode ProcessServiceRequest(XmlNode request);...
5
by: Christof Nordiek | last post by:
When I load a XML-Document from a file, and then get an XmlNode from it, is there any way to get the its original position in the file (line, character)? I want to report it, when there is...
0
by: rawatgaurav81 | last post by:
I had this strange problem in handling XMLDocuments in asp.net.Though the problem occurs while working on the main application.I will try to explain it with shorter code. I had a form with 2...
5
by: GarryJones | last post by:
To show users how many characters they have left in a TEXTAREA input I have been using "taCount" from a website I googled. function taCount(visCnt) { var taObj=event.srcElement; if...
3
by: aredz | last post by:
Hi, I want to extract the data inside an xmlData to a string. Let's say I (for example) I have this XML data: <text display-inline="yes">This<b>is</b>only<ref>a</ref><i>sample</i></text> ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.