 | Level: Intermediate Brett D. McLaughlin, Sr. (brett@newInstance.com), Author and Editor, O'Reilly Media, Inc.
10 Jun 2008 XML is a data format concerned primarily with compatibility and flexibility. But as useful as XML is, it's limited without the abilities to find specific portions of a document quickly and to filter and selectively locate data within a document. XPath provides the ability to easily reference specific text, elements, and attributes within a document—and with a fairly low learning curve. Additionally, XPath is key to many other XML vocabularies and technologies, such as XSL and XQuery. This tutorial will teach you the fundamentals of XPath, including all of its various selectors and semantics, in an example-driven and hands-on manner.
In this tutorial
Part 1 of this tutorial details the XPath specification, which allows you to specify particular sections of an XML document using a directory-like syntax. You'll learn the syntax of XPath, and you'll work with tools that let you experiment with XPath. By the time you complete this tutorial, you'll be well beyond the basics of XPath. You'll have a solid understanding of nodes, wildcards, and how XPaths are evaluated, and you'll be able to combine the results of two different XPaths.
Objectives - Set up your (Windows or Mac OS X) environment for the examples
- Select elements
- Select elements regardless of nesting
- Select attributes
- Widen your search with wildcards and the | operator
- Review briefly the use of nodes in XPath
Prerequisites
This tutorial is written for XML document authors and programmers. You should be familiar with and comfortable reading, writing, and manipulating XML. You should also be familiar with XML concepts, including the following:
- Elements
- Attributes
- Text
- The root element
Familiarity with the Document Object Model (DOM) is helpful for understanding nodes, but is not required. If you want to read up on the DOM, visit the Resources in the tutorial for several relevant links. This tutorial will mention several other APIs and specifications as well, including XSL, XSLT, and XPath. Knowledge of any of these is helpful, but not required. For more information on any of these, consult the Resources in the tutorial.
System requirements
You will need JavaScript enabled in your browser. You'll work with an XML document throughout this tutorial. You'll need to have this
document accessible on your machine, and you'll need to be familiar with the basic
structure of the document. Additionally, you'll need a tool that executes your XPath
locations and gives you feedback on what you've selected. The tutorial explains how to get all of this working on your personal environment so you can follow along with the tutorial examples. Tools to evaluate XPath locations are still specific to each operating system. Some of the nicer tools that download as EXE files and run on Microsoft® Windows® won't work on Mac OS X. Similarly, the tools to work with XPath on Mac OS X won't run on Windows. While you can use Java™ programs and classes to create a system-independent means to work with XPath, this tutorial focuses on XPath rather than any particular programming language.
- To work with XPath and XML documents on the Windows platform, download
and install Stylus Studio 2008 XML.
- To enable easy XPath location evaluation on Mac OS X, download and
install AquaPath .
Duration
1 hour
Formats html, pdf
|  | |  |