473,605 Members | 2,507 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xmlNode.InnerTe xt vs. xmlNode.Value

Dan
I've loaded the following xml into an XMLDocument object:

<?xml version="1.0" ?>
- <Preferences>
<Institution>Ar gh</Institution>
<Speaker>Chigie r, Ben (1234)</Speaker>
<Worktype>Adden dum</Worktype>
<speakerCode>12 34</speakerCode>
</Preferences>

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

string s = myxmldoc.Select SingleNode("/Preferences/Institution").V alue;

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.Select SingleNode("/Preferences/Institution").I nnerText;

Anyone know what's going on?

Thanks...

Dan
Nov 12 '05 #1
3 23580
"Dan" <da*@dontspamme .com> wrote in message news:ep******** ******@TK2MSFTN GP15.phx.gbl...
string s = myxmldoc.Select SingleNode("/Preferences/Institution").V alue;

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.Select SingleNode("/Preferences/Institution").I nnerText;

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


Dan wrote:
I've loaded the following xml into an XMLDocument object:

<?xml version="1.0" ?>
- <Preferences>
<Institution>Ar gh</Institution>
<Speaker>Chigie r, Ben (1234)</Speaker>
<Worktype>Adden dum</Worktype>
<speakerCode>12 34</speakerCode>
</Preferences>

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

string s = myxmldoc.Select SingleNode("/Preferences/Institution").V alue;

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.Select SingleNode("/Preferences/Institution").I nnerText;

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.Inne rText or
XmlElement.Inne rXml properties to access the value of the element node."

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '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******** ******@TK2MSFTN GP15.phx.gbl...
I've loaded the following xml into an XMLDocument object:

<?xml version="1.0" ?>
- <Preferences>
<Institution>Ar gh</Institution>
<Speaker>Chigie r, Ben (1234)</Speaker>
<Worktype>Adden dum</Worktype>
<speakerCode>12 34</speakerCode>
</Preferences>

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

string s = myxmldoc.Select SingleNode("/Preferences/Institution").V alue;

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.Select SingleNode("/Preferences/Institution").I nnerText;

Anyone know what's going on?

Thanks...

Dan

Nov 12 '05 #4

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

Similar topics

0
3558
by: Jocelyn Kwok | last post by:
Hi all, When I try to use XmlSerializer to serialize an ArrayList object which contains XmlNode objects, I got the "InvalidOperationException: The type System.Xml.XmlElement may not be used in this context." I can serialize an ArrayList object with string value and also an XmlNode object individually without problem. I have no idea why these two together can't work.
2
25211
by: Leszek | last post by:
Hello, I have the following code: // Read the XML document from the hard-drive. XmlDocument doc = new XmlDocument(); doc.Load("doc.xml"); // Create the document's root. XmlElement root = doc.DocumentElement;
5
5096
by: Paul | last post by:
Here I have the definition of an XmlNode which is a property (PayPreference) on my Customer class containing an enum describing how the customer will pay. <PayPerference xsi:type="a4:Customer+CustomerPayOptions" xmlns:a4="http://schemas.microsoft.com/clr/nsassem/OsfDomain.Resources.Stage/OsfDomain%2C%20Version%3D1.0.0.1%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">cash</PayPerference> I now want to add this XmlNode to a different...
3
19636
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> <Worktype>Addendum</Worktype> <speakerCode>1234</speakerCode> </Preferences>
2
13970
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> <text>Text of promotión 1</text>
0
1304
by: Philip Wagenaar | last post by:
I have an XML file that will contain the data of a binary file in MIME encoding. My application receiver the XML file with the location of the binary file: <REQUEST> <IMPORT> <DOCUMENT> <FIELD> <DATA>c:\myfile.dat</DATA> </FIELD>
1
4938
by: RJN | last post by:
Hi I have to read an xml and add the node elements into a hashtable with nodename as key and nodetext as value. If the selected node has childnodes, then value should go as an array. for eg., <Root> <mysection>
0
1699
by: RJN | last post by:
Hi I have to read an xml and add the node elements into a hashtable with nodename as key and nodetext as value. If the selected node has childnodes, then value should go as an array. for eg., <Root> <mysection>
5
8498
by: Steve Harclerode | last post by:
I saw something in the Microsoft documentation for SelectNodes() that I've never noticed before today: ----- Return Value The first XmlNode that matches the XPath query or a null reference (Nothing in Visual Basic) if no matching node is found. The XmlNode should not be expected to be connected "live" to the XML document. That is, changes that appear in the XML document may not appear in the XmlNode, and vice versa. -----
0
8004
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8418
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6743
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5886
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5445
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3912
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2438
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1541
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1271
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.