XML-specific features and guidance
Table of Contents Language Info for Maven POM Language Info for WSDL Language Info for XML Language Info for XSL The XML language modulePMD has an XML language module which exposes the DOM of an XML document as an AST. Different flavours of XML are represented by separate language instances, which all use the same parser under the hood. The following table lists the languages currently provided by the pmd-xml
maven module.
Each of those languages has a separate rule index, and may provide domain-specific XPath functions. At their core they use the same parsing facilities though.
File attributionAny file ending with .xml
is associated with the xml
language. Other XML flavours use more specific extensions, like .xsl
.
Some XML-based file formats do not conventionally use a .xml
extension. To associate these files with the XML language, you need to use the --force-language xml
command-line arguments, for instance:
$ pmd check -d /home/me/src/xml-file.ext -f text -R ruleset.xml --force-language xml
Please refer to PMD CLI reference for more examples.
XPath rules in XMLWhile other languages use XPathRule
to create XPath rules, the use of this class is not recommended for XML languages. Instead, since 6.44.0, you are advised to use DomXPathRule
. This rule class interprets XPath queries exactly as regular XPath, while XPathRule
works on a wrapper for the DOM which is inconsistent with the XPath spec. Since DomXPathRule
conforms to the XPath spec, you can
text()
or fn:string
Note: The Rule Designer only works with XPathRule
, and the tree it prints is inconsistent with the DOM representation used by DomXPathRule
. You can use an online free XPath testing tool to test your query instead.
Hereâs an example declaration of a DomXPathRule
:
<rule name="MyXPathRule"
language="xml"
message="A message"
class="net.sourceforge.pmd.lang.xml.rule.DomXPathRule">
<properties>
<property name="xpath">
<value><![CDATA[
/a/b/c[@attr = "5"]
]]></value>
</property>
<!-- Note: the property "version" is unsupported. -->
</properties>
</rule>
The most important change is the class
attribute, which doesnât point to XPathRule
but to DomXPathRule
. Please see the Javadoc for DomXPathRule
for more info about the differences with XPathRule
.
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