Understand how you can use XPath Expressions to navigate through elements in an XML document in Adobe FrameMaker.
An XML document consists of a hierarchy of elements. An XPath expression is used to navigate through elements and attributes in an XML document.
Given the following XML file:
<topic id="abc">
<title>Using XPATH</title>
<body>
<p>Using XPATH is easy.</p>
<fig>
<image href="images/xpath.png"/>
</fig>
<section>
<title>Examples</title>
<p audience="novice">A simple example.</p>
<p audience="expert">An advanced example.</p>
<p audience="expert">Another advanced example.</p>
<fig>
<image href="images/xpath-axes.png">
<alt>This screenshot shows the XPATH axes</alt>
</image>
</fig>
</section>
<p>The End.</p>
</body>
</topic>
The following table contains a list of some XPath expressions for the XML example given above.
XPath Query |
Locates |
---|---|
|
Returns the |
|
Returns any |
|
Returns only the |
|
Returns any |
|
Returns any |
|
Returns any |
|
Returns any |
|
Returns any |
|
Returns any |
|
Returns any |
For more information on XPath, see http://www.w3.org/TR/xpath/
Choose XPath toolbar.
to open theIn the XPath field, enter the XPath expression and click the Run button.
The results of the query are shown in the XPath Builder panel.
The Query Builder is also a convenient interface to build XPath expressions. 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
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 expression as you create the query.
For example, in the following XML:
<body>
<p>The quick brown fox.</p>
<p audience="admin">Jumped over the lazy dogs.</p>
</body>
In the Query Builder field start with entering a forward slash (/).
As soon as you enter the forward slash, the following suggestions display:
Use the up and down arrow keys to select the option and press Enter to insert the component into the query.
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:
Elements at the current position in the current document.
Attributes at the current position in the current document.
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.
Click the Save icon to save the current results of the XPath query.