XPath queries

An XML document consists of a hierarchy of elements. An XPath query is used to navigate through elements and attributes in an XML document.

For example to search for the paragraphs in the following XML document:

   <p>The quick brown fox.</p>
   <p>Jumped over the lazy dogs.</p>

The XPath search returns two results for the following XPath query:


If you have specified an attribute value for one of the elements:

   <p>The quick brown fox.</p>
   <p audience = "admin">Jumped over the lazy dogs.</p>

Include the attribute value in the search:


The XPath search returns one result.

The following table contains a list of sample XPath queries:

XPath Query



The <task> element where it is a top-level node in an XML file


The <task> element anywhere in an XML file


A <task> element where the id attribute has the value shovellingsnow


All the <title> elements that are direct decedents of <task> elements


All the <title> elements that occur anywhere in a <task> element

For more information on XPath, see http://www.w3.org/TR/xpath/

XPath toolbar

1)Open the XPath toolbar (View > Toolbars > XPath).

XPath toolbar


2)In the XPath field, enter the query and click Run.

The results of the query display in the XPath Builder pod.

XPath Builder pod


The Query Builder is also a convenient interface to build XPath queries. In the Query Builder, you can create (using Auto-Suggest functionality) and run an XPath query.

You can also specify the scope of the search:

Current File

All Open Files

Selected folder

DITA Map or Book - This option is available if you select a DITA Map or book in the Resource Manager


The Auto-Suggest feature provides suggested components that you can add to the XPath query as you create the query.

For example, in the following XML:

   <p>The quick brown fox.</p>
   <p audience = "admin">Jumped over the lazy dogs.</p>

1)In the Query Builder field start with entering a forward slash (/).

As soon as you enter the forward slash, the following suggestions display:



2)Use the up and down arrow keys to select the option and press enter to insert the component into the query.

3)To add another element to the query, enter a forward slash.

Alternatively, to add an attribute, enter an opening square bracket ([).

The Auto-Suggest list contains the following components of an XPath query:

Element (Orange indicator)

Elements at the current position in the current document.

Attribute (Blue indicator)

Attributes at the current position in the current document.

Axes (Green indicator)

An axis is a node definition relative to the current node. For example, parent, child, ancestor.

Click the drop-down list to the right of the Enable Auto-Suggest option and un-check the Axes option to hide the available axes in the Auto-Suggest list.

note:    You can choose to disable the Auto-Suggest feature in the Query Builder.

Click the Save icon to save the current results of the XPath query.

September 30, 2016

Legal Notices | Online Privacy Policy