LINQ to XML classes overview

This article provides a list of the LINQ to XML classes in the System.Xml.Linq namespace, and a short description of each.

LINQ to XML classes

XAttribute class

XAttribute represents an XML attribute. For detailed information and examples, see XAttribute class overview.

XCData class

XCData represents a CDATA text node.

XComment class

XComment represents an XML comment.

XContainer class

XContainer is an abstract base class for all nodes that can have child nodes. The following classes derive from the XContainer class:

XDeclaration class

XDeclaration represents an XML declaration. An XML declaration is used to declare the XML version and the encoding of a document. In addition, an XML declaration specifies whether the XML document is stand-alone. If a document is stand-alone, there are no external markup declarations, either in an external DTD, or in an external parameter entity referenced from the internal subset.

XDocument class

XDocument represents an XML document. For detailed information and examples, see XDocument class overview.

XDocumentType class

XDocumentType represents an XML Document Type Definition (DTD).

XElement class

XElement represents an XML element. For detailed information and examples, see XElement class overview.

XName class

XName represents names of elements (XElement) and attributes (XAttribute). For detailed information and examples, see XDocument class overview.

LINQ to XML is designed to make XML names as straightforward as possible. Due to their complexity, XML names are often considered to be an advanced article in XML. Arguably, this complexity comes not from namespaces, which developers use regularly in programming, but from namespace prefixes. Namespace prefixes can be useful to reduce the keystrokes required when you input XML, or to make XML easier to read. However, prefixes are often just a shortcut for using the full XML namespace, and aren't required in most cases. LINQ to XML simplifies XML names by resolving all prefixes to their corresponding XML namespace. Prefixes are available, if they're required, through the GetPrefixOfNamespace method.

it's possible, if necessary, to control namespace prefixes. In some circumstances, if you're working with other XML systems, such as XSLT or XAML, you need to control namespace prefixes. For example, if you have an XPath expression that uses namespace prefixes and is embedded in an XSLT stylesheet, you must make sure that your XML document is serialized with namespace prefixes that match those used in the XPath expression.

XNamespace class

XNamespace represents a namespace for an XElement or XAttribute. Namespaces are a component of an XName.

XNode class

XNode is an abstract class that represents the nodes of an XML tree. The following classes derive from the XNode class:

XNodeDocumentOrderComparer class

XNodeDocumentOrderComparer provides functionality to compare nodes for their document order.

XNodeEqualityComparer class

XNodeEqualityComparer provides functionality to compare nodes for value equality.

XObject class

XObject is an abstract base class of XNode and XAttribute. It provides annotation and event functionality.

XObjectChange class

XObjectChange specifies the event type when an event is raised for an XObject.

XObjectChangeEventArgs class

XObjectChangeEventArgs provides data for the Changing and Changed events.

XProcessingInstruction class

XProcessingInstruction represents an XML processing instruction. A processing instruction communicates information to an application that processes the XML.

XText class

XText represents a text node. In most cases, you don't have to use this class. This class is primarily used for mixed content.