The LINQ to XML Object Model

With the new LINQ to XML API comes a new object model containing many new classes that exist in the System.Xml.Linq namespace. One is the static class where the LINQ to XML extension methods live, Extensions; two are comparer classes, XNodeDocumentOrderComparer and XNodeEqualityComparer, and the remaining are used to build your XML trees. Those remaining classes are displayed in the diagram shown in Figure 7-1.

LINQ to XML API object model

There are some interesting things to notice:

  1. Of those remaining classes, three are abstract, XObject, XContainer, and XNode, so you will never be constructing them.

  2. An attribute, XAttribute, is not derived from a node, XNode. In fact, it is not a node at all but instead is a totally different type of class that is basically a name-value pair.

  3. Streaming elements, XStreamingElement, have no inheritance relationship with elements, XElement.

  4. The XDocument and XElement classes are the only classes that have child nodes derived from XNode.

These are the classes you will use to build your XML trees. Most notably, you will use the XElement class, because as I have already discussed, the LINQ to XML API is very element-centric, as opposed to document-centric like the W3C XML DOM.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset