Quackit Logo

FREE Hosting!

With every domain name you register with ZappyHost, you get FREE hosting.

$1.99 Domain Names

With every new non-domain purchase thru ZappyHost, you get a domain name for only $1.99.

XPath Introduction

Print Version

XPath is a language that enables you to navigate, and find data, within your XML documents. Using XPath, you can select one or more nodes in order to retrieve the data they contain.

Actually, we've already used XPath in this XML tutorial - we used it to program some of our XSL transformations. XPath is used quite extensively with XSLT. Once you start learning XPath, you'll see how suited it is to XSLT.

XPath Purpose

Since XPath is used for finding data within XML documents, this enables you to write applications that make use of the data within an XML document.

In fact, in order to use XSLT (to transform the contents of your XML documents), you need to use XPath.

Other XML based languages such as XQuery and XPointer also rely on XPath expressions, so XPath really does play an important role when writing XML applications.

Consider the following XML document:

<albums>
  <rock>
    <title>Machine Head</title>
    <artist>Deep Purple</artist>
  </rock>
  <blues>
    <title>Greens From The Garden</title>
    <artist>Cory Harris</artist>
  </blues>
  <country>
    <title>The Ranch</title>
    <artist>The Ranch</artist>
  </country>
</albums>

What are some of the things we might be interested in when writing an application? We might need to extract the title of all albums for example. Or, we might only be interested in the artists. Or, we might only be interested in albums and artists from a specific niche, such as rock.

XPath allows us to select only the nodes we're interested in.

Enjoy this website?

  1. Link to this page (copy/paste into your own website or blog):
  2. Add this page to your favorite social bookmarks sites:
               
  3. Add this page to your Favorites

Oh, and thank you for supporting Quackit!