Connecting Tech Pros Worldwide Help | Site Map

What is the difference between XmlNode and XmlElement?

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 11th, 2005, 10:06 PM
Pluto
Guest
 
Posts: n/a
Default What is the difference between XmlNode and XmlElement?

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.



  #2  
Old November 11th, 2005, 10:06 PM
Oleg Tkachenko
Guest
 
Posts: n/a
Default Re: What is the difference between XmlNode and XmlElement?

Pluto wrote:
[color=blue]
> What is the difference between XmlNode and XmlElement?[/color]
The same as between fruit and apple. XmlElement is particular type of
XmlNode.
[color=blue]
> this.appSettingsElement =
> this.xml.SelectSingleNode("//configuration/appSettings");
>
> Error: Cannot implicitly convert type 'System.Xml.XmlNode' to
> 'System.Xml.XmlElement'[/color]

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

--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

  #3  
Old November 11th, 2005, 10:07 PM
Peter Rilling
Guest
 
Posts: n/a
Default Re: What is the difference between XmlNode and XmlElement?

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.

"Oleg Tkachenko" <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message
news:e7Q3XKSjDHA.2592@TK2MSFTNGP10.phx.gbl...[color=blue]
> Pluto wrote:
>[color=green]
> > What is the difference between XmlNode and XmlElement?[/color]
> The same as between fruit and apple. XmlElement is particular type of
> XmlNode.
>[color=green]
> > this.appSettingsElement =
> > this.xml.SelectSingleNode("//configuration/appSettings");
> >
> > Error: Cannot implicitly convert type 'System.Xml.XmlNode' to
> > 'System.Xml.XmlElement'[/color]
>
> So convert it explicitly:
> this.appSettingsElement =
> (XmlElement)this.xml.SelectSingleNode("//configuration/appSettings");
>
> --
> Oleg Tkachenko
> http://www.tkachenko.com/blog
> Multiconn Technologies, Israel
>[/color]


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.