Psst! Did you know DevelopmentNow is a mobile web site design agency?

Contact us for help mobilizing your site, or to sign up for our beta Mobile Web SDK!
all groups > dotnet xml > october 2003 >

dotnet xml : What is the difference between XmlNode and XmlElement?


Pluto
10/7/2003 3:19:31 PM
What is the difference between XmlNode and XmlElement?

I'm trying to implement the code at
http://www.devx.com/dotnet/Article/11616/0/page/3 in C# and I'm getting an
error at this line:
this.appSettingsElement =
this.xml.SelectSingleNode("//configuration/appSettings");

Error: Cannot implicitly convert type 'System.Xml.XmlNode' to
'System.Xml.XmlElement'

Thanks.

Oleg Tkachenko
10/8/2003 12:30:10 AM
[quoted text, click to view]
The same as between fruit and apple. XmlElement is particular type of
XmlNode.

[quoted text, click to view]

So convert it explicitly:
this.appSettingsElement =
(XmlElement)this.xml.SelectSingleNode("//configuration/appSettings");

--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel
Peter Rilling
10/8/2003 11:05:09 AM
But as for the difference between the two, a node is more general then an
element. Anything in an XML document is a node (e.g. attributes, comments,
doctype, etc), but only tags are elements.

This error is not specific to XML conversions but .NET cannot implicitly
down-cast a variable. That is why you need to specify the cast yourself
since SelectSingleNode returns an XmlNode object.

[quoted text, click to view]

Daniel Cazzulino
11/7/2003 3:58:47 PM
Yup, Peter's right. To further understand it, you could write an XPath
expression like the following:

this.xml.SelectSingleNode(//configuration/appSettings/add/@key);

Where the result wouldn't be "castable" to XmlElement altogether, as it
would return the key ("myKey") attribute of hte section:

<configuration>
<appSettings>
<add key="myKey" value="myValue"/>



[quoted text, click to view]

name
11/9/2003 3:34:30 AM
You have 3 hard coded path 'variables' in your post.


What is this standardized (ly) supposed to mean?

==============


You are an MS love child ?

---------

'castable,key' ==== never


+++++++

Any furry animal be anywhere earlier.

simply by natural evolution.

======

Be good to Ms, buy some more of their wonders.

____

Anyway my thumb up to you.





[quoted text, click to view]
Daniel Cazzulino
11/13/2003 10:07:38 AM
What do you mean by "hard coded path 'variables' "??? The expression has no
variables:

this.xml.SelectSingleNode("//configuration/appSettings/add/@key");

The quotes were missing, that's all. that would return an XmlAttribute node.
And I certainly don't get everything you say below that sentence... maybe
you want to explain what you meant..


[quoted text, click to view]

AddThis Social Bookmark Button