XPath Expression Evaluation
Evaluating XPath expressions in CLion has two main purposes: Testing XPath expressions that are to be used in program code or XSLT scripts, and making structured queries against XML documents. The Evaluate XPath action can be invoked either from the editor context menu, the main Search Menu or the main toolbar by clicking the action's icon .
The Expression Evaluation has two different modes, a simple mode, that allows you to enter simple one-line expressions and doesn't allow you to configure and Context settings. For more convenient editing of long expressions in a multi-line style way, there's the advanced mode dialog that also has a button to edit some context settings, such as namespaces and their prefixes, and variables to use for the evaluation.
Both dialogs feature 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 (e.g.
@comment()) and node tests for element/attribute
names that don't occur in the context document and would not be successfully matched.
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.
The simple mode comes with an input field that can be used to enter simple one-line expressions that don't require any customization of namespace prefixes or make use of predefined variables. The last recently used expressions can be selected from the drop-down list.
The advanced mode adds the possibility to edit expressions in a multiline editor and has another button to edit the XPath Context. The expression history can be browsed by the Up- and Down arrays on the right of the dialog or the keyboard shortcuts for the previous/next history element (usually Ctrl-Alt-Up, Ctrl-Alt-Down).
This dialog allows you to assign custom prefixes to the namespace URIs that are used in the context document. This 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.
The XPath Context also includes the possibility to define custom XPath variables that can be used in queries for repeating expressions. 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.
This highlights 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 toolwindow.
Show results in usage view
Shows all matched nodes in the Find Usages toolwindow. Check Open in new tab to open the result in a new tab instead of reusing the last one.