Introduction to the XPath Specification
Just like DOM, XPath operates on a tree-based view of an XML document. The XPath tree is built of the same node types used in DOM, except that CDATA sections, entity references, and document type declarations are not directly addressable. Their content is, however; the net result is that you can navigate to a text node’s content, but you cannot tell whether that content contains plain text, CDATA, expanded entity references, or some combination thereof. You cannot access document type declarations at all with XPath.
For this discussion, I’ll return to the inventory example from Chapter 5. That example included an inventory database that looked similar to the one in Example 6-1; here I’ve added some additional products.
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE inventory SYSTEM "inventory.dtd"> <inventory> <!-- Warehouse inventory for Angus Hardware --> <date year="2002" month="7" day="6" /> <items> <item quantity="15" productCode="R-273" description="14.4 Volt Cordless Drill" unitCost="189.95" /> <item quantity="23" productCode="1632S" description="12 Piece Drill Bit Set" unitCost="14.95" /> <item quantity="10023" productCode="GN0250" description="1/4 inch Galvanized Steel Nails, 1/2 pound box" unitCost="4.95" /> <item quantity="9887" productCode="GN0375" description="3/8 inch Galvanized Steel Nails, 1/2 pound box" unitCost="189.95" /> <item quantity="8761" productCode="GN0500" description="1/2 ...
Get .NET & XML now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.