O'Reilly logo

LINQ Pocket Reference by Joseph Albahari, Ben Albahari

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required