What is the difference between Xmldocument and Xelement?

Asked

Viewed 242 times

4

I’d like to know the difference between Xmldocument and Xelement.

1 answer

3


XmlDocument represents an entire XML document. It is possible to use this class to manipulate XML files.

XElement is a class of System.Xml.Linq, it is used to represent a single element within an XML document in the LINQ to XML.

You can use it to manipulate, get the value, remove, change the child elements of an element in an XML document.


Note that the class XmlDocument is part of namespace System.Xml while the class XElement is part of the System.Xml.Linq. In LINQ the class used to represent an XML document is the XDocument.

  • and xmlElement is the same thing as Xelement ?

  • @Standalone I missed the writing. It’s clearer now?

  • I have an Xmldocument and need to pass a Xelement to a method, in case you said xelement is a single xmldocument element right? I can get a xelement from an xmldocument or it has nothing to do ?

  • @Standalone Todo XmlDocument has a property called DocumentElement, this property is of the type XmlElement and represents the root element of the XML document. Similarly, every instance of XDocument has a property called Root of the kind XElement which has the same purpose. Note that XmlDocument and XElement are part of two distinct Apis.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.