|
An XML file appears as an upside-down tree: it has a root
(in this case <Videos>), it can have branches (in this case <Video>), and
it can have leaves (an example in this case is <Title>). As we have seen so far, all of
these objects are created using the same technique: a tag with a name (such as
<Title>) and an
optional value. Based on their similarities, each of these objects is called a
node. To support nodes of an XML file, the .NET Framework
provides the XmlNode class, which is the ancestor to all types of nodes.
XmlNode is an abstract class without a constructor. Based on this, to get
a node, you must have an object that would produce one and you can only retrieve
a node from an (existing) object.
|

|
|
Introduction to Node Types |
|
|

|
To make XML as complete and as efficient as possible, it can
contain various types of nodes. The categories or possible types of nodes are identified by an
enumeration named XmlNodeType. If you use an XmlTextReader object
to scan a file, when calling Read(), the class has a property
named NodeType that allows you to identify the node that was read. NodeType
is a read-only property of type XmlNodeType and it is declared as
follows:
public override XmlNodeType NodeType { get; }
|
Therefore, when calling the XmlTextReader.Read()
method, you can continuously check the value of the XmlTextReader.NodeType
property to find out what type of node was just read, and then you can take an
appropriate action.
|
|