Programming with the XML Document Object Model




The XML DOM offers complete programmatic access to XML data. When working with the DOM, you
approach your XML data as a tree of nodes, which starts from the root element and continues for as
many levels of depth as your data structure requires. In this section, you learn about the classes of the
DOM that enable you to navigate the DOM tree structure, read and change data, and also generate new
XML structures in your application code.

There are two ways to navigate the XML document hierarchy. One option is to move through the node
hierarchy from parent node to child nodes, for as many levels of nesting as the data contains. The other
option is to use methods such as GetElementsByTagName, GetElementById, SelectNodes, or

SelectSingleNode to directly locate one or many nodes that match selection criteria. SelectNodes

and SelectSingleNode useXPath expressions to specify selection criteria. This is covered later in this
chapter, in the section titled “XPath Support in XML DOM.”

Each node in a document is one of the specialized types of nodes defined by the DOM. A node can rep-
resent the document itself, or an element, an attribute, text content, a processing instruction, a comment,
or any of the other items that are valid in an XML file. The base class of XmlNode defines the basic set of
properties and methods for all types of nodes. Each specialized type of node, which is a class derived
from the XmlNode base class, has some additional properties and methods that are unique to that node
type’s characteristics. XmlNode is the abstract parent class of a handful of node-related classes that are
available in the .NET Framework. Figure 6-2 shows the hierarchy of node classes.

Both XmlLinkedNode and XmlCharacterData are abstract classes that provide basic functionality for
more specialized types of nodes. Linked nodes are nodes that you might find as constituent elements of
an XML document just linked to a preceding or a following node. Character data nodes, on the other
hand, are nodes that contain and manipulate only text.


learn guitarphysics learnteliphonyxmlphysicsenjoylife