The X-Files: XPath, XPointer, and XLink
IN THIS CHAPTER
Now that you have a decent understanding of what XML is, the next obvious question is how can we find the pieces of information we desire. The answer is the XML Path Language, or XPath. The XML Path Language provides a standard syntax for querying an XML document for specific pieces of information. This syntax provides an indepen-dent mechanism for “querying” or locating the desired elements or attributes within the XML document.
XPath, itself, is a very powerful mechanism for finding the elements or attributes you want to work with. Imagine if you had to traverse the hierarchy one element and one attribute at a time and perform a conditional test to see whether the current element or attribute matched the search criteria you specified. For small XML documents, you prob-ably wouldn’t notice much. However, for larger XML documents, the speed issue imme-diately appears. This is one of the reasons XPath was created—to reduce the amount of time to find the elements and attributes desired by an author or developer.
XLink allows an XML document to specify a link from the current document to another document in another location. This facilitates the dispersion and compartmentalization of data much the same way a normalized database would. You could think of each docu-ment as a table within a database and the XLink specification of each document as a relation between the tables. This means instead of having to duplicate information among the documents, you could specify information once and be able to access it via XLink.
XPointer expands on the functionality of XLink by building on the XPath specification and identifying a node or node set to link to in the target document. This provides much the same functionality as a foreign key within a table of a database. Because the informa-tion within a normalized database exists in one location only, it becomes necessary to relate to that information to prevent duplication of information. XPointers provide the same functionality within a group of XML documents.
In this chapter, you will learn
What namespaces are and how they can be useful within an XML document
The relationship among XPath, XLink, and XPointer
What XPath is and how it can be used to find the desired node(s) within an XML document
The syntax of an XPath expression
How XPointer can be used to locate specific nodes within a related XML document
How XLink can be used to link various XML documents together