XPath expression evaluation
An XPath expression needs evaluation to test it before using in program code or XSLT scripts or before making structured queries against XML documents.
PhpStorm lets you evaluate XPath expressions in two modes:
In the Simple mode, you can enter simple one-line expressions that don't require any customization of namespace prefixes. This mode does not let you configure Context settings or use predefined variables.
In the Advanced mode, you can conveniently edit long expressions in a multi-line mode and edit the XPath context.
Some error checks and XPath inspections also provide Quick Fixes for detected problems, e.g. the possibility to map an unresolved namespace-prefix to a URI by intention.
Evaluate an XPath expression
Choose Evaluate XPath Expression dialog opens.from the context menu of the active editor tab or go to . The
To toggle the evaluation mode, click the Advanced/Simple button. In either mode, the dialog features a history of the recently evaluated expressions, completion, syntax-checking and highlighting, as well as some semantic error checking of the entered expression. Semantic checks include validation of used namespace prefixes, useless XPath expressions (for example,
@comment()) and node tests for element/attribute names that don't occur in the context document and would not be successfully matched.
- To browse through the history of expressions:
In the Simple mode, the last recently used expressions can be selected from the drop-down list.
In the Advanced mode, use / or press Alt+Up/Alt+Down.
- To reconfigure the XPath context, click Edit Context. In the dialog that opens, assign custom prefixes to the namespace URIs that are used in the context document and define variables to use in queries for repeating expressions.
It can be useful to assign a shorter prefix, resolve prefix clashes or to actually define a prefix for the default namespace. This can be essential because XPath does not automatically match elements in the default namespace without specifying a prefix for the element to be matched. edit namespaces and their prefixes and
Each variable in the table can be assigned an expression that will be evaluated once when the query is executed. The resulting value is then available for multiple use at no additional computational cost.
Select the Highlight results checkbox ti highlight the matched nodes in the current editor. Matched nodes that don't belong to the current editor (may happen by using the
document()function) are not highlighted. It's recommended to display such cross-document results in the Find Usages tool window.
Select the Show results in Usage View checkbox to show all matched nodes in the Find Usages tool window. Select the Open in new tab checkbox to open the result in a new tab instead of reusing the last one.