473,795 Members | 2,863 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.appSetting sElement =
this.xml.Select SingleNode("//configuration/appSettings");

Error: Cannot implicitly convert type 'System.Xml.Xml Node' to
'System.Xml.Xml Element'

Thanks.
Nov 11 '05 #1
2 65671
Pluto wrote:
What is the difference between XmlNode and XmlElement? The same as between fruit and apple. XmlElement is particular type of
XmlNode.
this.appSetting sElement =
this.xml.Select SingleNode("//configuration/appSettings");

Error: Cannot implicitly convert type 'System.Xml.Xml Node' to
'System.Xml.Xml Element'


So convert it explicitly:
this.appSetting sElement =
(XmlElement)thi s.xml.SelectSin gleNode("//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 SelectSingleNod e returns an XmlNode object.

"Oleg Tkachenko" <oleg@NO_SPAM_P LEASEtkachenko. com> wrote in message
news:e7******** ******@TK2MSFTN GP10.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.appSetting sElement =
this.xml.Select SingleNode("//configuration/appSettings");

Error: Cannot implicitly convert type 'System.Xml.Xml Node' to
'System.Xml.Xml Element'


So convert it explicitly:
this.appSetting sElement =
(XmlElement)thi s.xml.SelectSin gleNode("//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
377
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 to XmlElement but can not cast the returned node to XmlElementCF, I am getting an error : Specified cast is not valid. I want to cast the returned node to my inherited class XmlElementCF. Please Help. Thanks Parham
0
3572
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
25257
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;
2
10390
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" value="server=(local);" /> </appSettings> </configuration> I am using a XmlDocument for my base implementation.
1
1407
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 { return extra;} set { extra = value;}} However, if I have: <Something>
2
1492
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 values by XPath having an XmlNode representing the <offer> element. Now when I try something like this
1
4744
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 liefert mir ein element des typs node.
5
3884
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 XMLDocument and my first question is why does this work? XmlNode neNode; neNode = myHFCService.GetPOs(); DataSet myds = new DataSet();
4
13631
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 takes only XmlAttribute and in this when I create a new XmlAttribute, it doesn't allow me to set the name and value as the name is only the readonly value. How can I achive this?
0
9522
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10216
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...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9044
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...
0
6783
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
5437
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...
0
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
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
2
3728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.