A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.pmd-code.org/apidocs/pmd-xml/7.0.0/net/sourceforge/pmd/lang/xml/rule/DomXPathRule.html below:

DomXPathRule (PMD XML and XSL 7.0.0 API)

XPath rule that executes an expression on the DOM directly, and not on the PMD AST wrapper. The XPath expressions adheres to the XPath (2.0) spec, so they can be tested in any existing XPath testing tools instead of just the PMD designer (google "xpath test"). Usage of this class is strongly recommended over the standard

XPathRule

, which is mostly useful in other PMD languages.

Differences with XPathRule

This rule and

XPathRule

do not accept exactly the same queries, because

XPathRule

implements the XPath spec in an ad-hoc way. The main differences are:

Additionally, this rule only supports XPath 2.0, with no option for configuration. This will be bumped to XPath 3.1 in PMD 7.

Namespace-sensitivity

Another important difference is that this rule is namespace-sensitive. If the tested XML documents use a schema (xmlns attribute on the root), you should set the property defaultNsUri on the rule with the value of the xmlns attribute. Otherwise node tests won't match unless you use a wildcard URI prefix (*:nodeName).

For instance for the document


 <foo xmlns="http://company.com/aschema">
 </foo>
 

the XPath query

//foo

will not match anything, while

//*:foo

will. If you set the property

defaultNsUri

to

"http://company.com/aschema"

, then

//foo

will be expanded to

//Q{http://company.com/aschema}foo

, and match the

foo

node. The behaviour is equivalent in the following document:


 <my:foo xmlns:my='http://company.com/aschema'>
 </my:foo>
 

However, for the document


 <foo>
 </foo>
 

the XPath queries

//foo

and

//*:foo

both match, because

//foo

is expanded to

//Q{}foo

(local name foo, empty URI), and the document has no default namespace (= the empty default namespace).

Note that explicitly specifying URIs with Q{...}localName as in this documentation is XPath 3.1 syntax and will only be available in PMD 7.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4