XPath Location Path - Absolute

A quick overview of absolute location paths.

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:

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

The Result

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

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:

Option 2 - use a forward slash: