The Tree Structure of an XML Document
An XML document is a tree made up of nodes. Some nodes contain one or more other nodes. There is exactly one root node, which ultimately contains all other nodes. XPath is a language for picking nodes and sets of nodes out of this tree. From the perspective of XPath, there are seven kinds of nodes:
The root node
Element nodes
Text nodes
Attribute nodes
Comment nodes
Processing-instruction nodes
Namespace nodes
One thing to note are the constructs not included in this list:
CDATA sections, entity references,
and document type declarations. XPath operates on an XML document
after all these items have been merged into the document. For
instance, XPath cannot identify the first CDATA section in a document or tell whether
a particular attribute value was directly included in the source
element start-tag or merely defaulted from the declaration of the
element in a DTD.
Consider the document in Example 9-1. This exhibits all seven kinds of nodes. Figure 9-1 is a diagram of the tree structure of this document.
<?xml version="1.0"?> <?xml-stylesheet type="application/xml" href="people.xsl"?> <!DOCTYPE people [ <!ATTLIST homepage xlink:type CDATA #FIXED "simple" xmlns:xlink CDATA #FIXED "http://www.w3.org/1999/xlink"> <!ATTLIST person id ID #IMPLIED> ]> <people> <person born="1912" died="1954" id="p342"> <name> <first_name>Alan</first_name> <last_name>Turing</last_name> </name> <!-- Did the word computer ...