473,395 Members | 1,484 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,395 software developers and data experts.

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.
Nov 11 '05 #1
2 65478
Pluto wrote:
What is the difference between XmlNode and XmlElement? The same as between fruit and apple. XmlElement is particular type of
XmlNode.
this.appSettingsElement =
this.xml.SelectSingleNode("//configuration/appSettings");

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


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

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

Nov 11 '05 #2
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:e7**************@TK2MSFTNGP10.phx.gbl...
Pluto wrote:
What is the difference between XmlNode and XmlElement?

The same as between fruit and apple. XmlElement is particular type of
XmlNode.
this.appSettingsElement =
this.xml.SelectSingleNode("//configuration/appSettings");

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


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

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

Nov 11 '05 #3

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

Similar topics

1
by: Parham | last post by:
Hello, I have an inherited class from XmlElement with this name: XmlElementCF I have added a function in XmlElementCF that returns a XmlNode, the node type is Element. I can cast the returned node...
0
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...
2
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 =...
2
by: David Elliott | last post by:
I am creating a configuration class to read / write a standard configuration file. <?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings> <add key="ConnectionString"...
1
by: Dominic Messenger | last post by:
I have a schema that I load into classes that mirror the schema using the XmlSerialization. The schema contains an xsd:Any that I load into 'Extra' as follows: public XmlNode Extra { get {...
2
by: J Mon | last post by:
I have a XML document with elements like <offer> <field name="name"><!]></field> <field name="merchant_id"><!]></field> ..... </offer> I know not the best XML! Now I am selecting different...
1
by: andrej | last post by:
hi, ich habe eine anwendung, welche ein xml document erstellt. um festzustellen, ob ein element bereits vorhanden ist, verwende ich die funktion selectsinglenode( ....) diese funktion...
5
by: GaryDean | last post by:
I have a web service method that returns an XMLDocument. The signature is: public XmlDocument GetPOs() The following client code calls this method but it accepts an XMLNode instead of an...
4
by: CSharper | last post by:
I am reading an XmlFile using XmlDocument and traverse through the XmlNode, as I read I need to append an attribute to the XmlNode on some conditions. I tried xmlNode.Attributes.Append() It...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.