Quackit Logo
HTML
CSS
Scripting
Database
Hosting
Design
XML
IMCreator - Free Website Builder

XPath Location Path - Absolute

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:

Code

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

Code

The Result

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

Code

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:

Code

Option 2 - use a forward slash:

Code

Enjoy this page?

  1. Link to this page (copy/paste into your own website or blog):
  2. Link to Quackit using one of these banner ads.

Thanks for supporting Quackit!