X-DOM Overview

Figure 1-11 shows the core X-DOM types. XElement is the most frequently used of these. XObject is the root of the inheritance hierarchy; XElement and XDocument are roots of the containership hierarchy.

Core X-DOM types

Figure 1-11. Core X-DOM types

Figure 1-12 shows the X-DOM tree created from the following code:

	string xml =
	@"<customer id='123' status='archived'>
	  <firstname>Joe</firstname>
	  <lastname>Bloggs<!--nice name -></lastname>
	</customer>";

	XElement customer = XElement.Parse (xml);
A simple X-DOM tree

Figure 1-12. A simple X-DOM tree

XObject is the abstract base class for all XML content. It defines a link to the Parent element in the containership tree as well as an optional XDocument.

XNode is the base class for most XML content, excluding attributes. The distinguishing feature of XNode is that it can sit in an ordered collection of mixed-type XNode’s. For instance, consider the following XML:

	<data>
	  Hello world
	  <subelement1/>
	  <!--comment-->
	  <subelement2/>
	</data>

Within the parent element <data>, there’s first an XText node (Helloworld ), then an XElement node, then an XComment node, and then a second XElement node. In contrast, an XAttribute will tolerate only other XAttribute’s as peers.

Although an XNode can access its parent XElement, it has no concept of child nodes; this is the job of its subclass ...

Get LINQ Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.