Quackit Logo
Sponsored Links
$1.99 Domain Names
With every new non-domain purchase thru ZappyHost, you get a domain name for only $1.99.
Create free Flash websites

XPath Location Path - Absolute

Print Version

As described in the previous lesson, a location path specifies the path through the XML document's hierarchy that you'd like to work with.

Your location path can be absolute or relative. If your location path starts with the root node or a forward slash (/) you are using an absolute location path - your location path begins from the root node.

If your location path begins with the name of a descendant, you're using a relative location path. This node is referred to as the context node.

We'll look at relative location paths in the next lesson. For now, let's look at absolute location paths.

Example of an Absolute Location Path

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>

If we wanted to select the "title" node of all albums, we could use the following (absolute) location paths:

albums/rock/title
albums/blues/title
albums/country/title

The Result

Here are the nodes that are selected using the above location path.

<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>

The Root Node

If we wanted to select the root node, we could use either the node's name or a forward slash. Both of these options are absolute location paths and select the root node.

Option 1 - use the root node's name:

albums

Option 2 - use a forward slash:

/

Enjoy this website?

  1. Add this page to your Favorites
  2. Link to this page (copy/paste into your own website or blog):
  3. Help support Quackit by making a donation
  4. Add this page to your favorite social bookmarks sites:      

Oh, and thank you for supporting Quackit!

FREE Hosting!
With every domain you register with ZappyHost you get FREE hosting.
Need Website Content?
Get unique, quality digital content for your website.
  • 270+ Website Templates
  • 800+ Flash Templates
  • 25,000+ Images, Logos
  • 30,000+ e-Books
  • 15,000+ Scripts
  • 27,000+ Animated GIFs
  • 21,000+ Ringtones
  • ...and much more!
Get your content now!
© Copyright 2000 - 2010 Quackit.com