|Querying Documents / Running XPath Expressions|
To use XPath expressions effectively, you need a good understanding of the XPath Core Function Library. Oxygen XML Author provides an XPath toolbar that eases the development of XML documents.
Syntax highlight is available in the XPath toolbar and allows you to identify the components of an XPath expression. To customize the colors of the components of an XPath expression, go to.
The content completion assistant is also available in the XPath toolbar. It offers context-dependent proposals and takes into account the cursor position in the document you are editing. The set of XPath functions proposed by the content completion assistant also depends on the XPath version. Select the XPath version from this drop-down menu on the XPath toolbar.
In the following figure, the content completion assistant offers element names from the current document and all XPath 2.0 functions:
Content Completion in the XPath toolbar
When Oxygen XML Author evaluates an XPath expression, it uses XML catalogs to resolve the location of documents referred in the expression. To configure XML catalogs, go to . .
An example is evaluating the collection(URIofCollection) function (XPath 2.0). To resolve the references from the files returned by the collection() function with an XML catalog, specify the class name of the XML catalog enabled parser for parsing these collection files. The class name is ro.sync.xml.parser.CatalogEnabledXMLReader. Specify it as it follows:
let $docs := collection(iri-to-uri( "file:///D:/temp/test/XQuery-catalog/mydocsdir?recurse=yes;select=*.xml; parser=ro.sync.xml.parser.CatalogEnabledXMLReader"))
Enable XPath update on caret move. to display the XPath expression at the current cursor position in the XPath toolbar, when you navigate through a document.
To arrange the results depending on a column click on its header. To group the results by their resource, or by their system id, right click the header of any column in the results view and select Group by "Resource" or Group by "System ID". If no information regarding location is available, Oxygen XML Author displays Not available in the Location column. Oxygen XML Author displays the results in a valid XPath expression format.
- /node[value]/node[value]/node[value] -
XPath results highlighted in editor panel with character precision
If you use the grid editor, when you click a record in the Results View, Oxygen XML Author highlights the entire node.
XPath results highlighted in the Grid Editor
When you type expressions longer than 60 characters, a dialog pops up and offers you the possibility to switch to the XPath builder view. The XPath builder view is specially designed to assist you with typing and testing complex XPath 1.0 / 2.0 expressions.
To find all example nodes contained in the sect2 nodes of a DocBook XML document, use the following XPath expression: //chapter/sect1/sect2/example. Oxygen XML Author adds a result in the Results View for each example node found in any sect2 node.
For example, if the result of the above XPath expression is:
it means that in the edited file the example node is located in the first chapter, third section level one, seventh section level 2.
To define default mappings between prefixes (that you can use in the XPath toolbar) and namespace URIs go to XPath Options preferences panel and enter the mappings in the Default prefix-namespace mappings table. The same preferences panel allows you to configure the default namespace used in XPath 2.0 expressions. Different results tabs are created for each executed XPath query.
To apply an XPath expression relative to the element on which the caret is positioned, use the following actions: