XPath help to create custom rules for xml

Hello All,

I am new to SonarQube tool and would like to use scan the couple of xml files (apigee proxy bundle). As part of this I would like perform custom checks in the xml files and for that I need to create custom rules.

As per the help from sonarqube, need to use xpath expression to add the rules. Can anyone help me with step-by-step procedure to write rules for xml.

Also I am using sonar-apigee-plugin-X.X.X.jar downloaded from here. Can anyone help me to how to change the existing rules under this plugin.

Thank you in advance.

Regards,
AK

Hello @Arjunkalikota,

Sorry for the delay answering you. i’m only going to answer the first part of your question, as I don’t know the apigee plugin.

There is no need to write custom rules (and therefore creating a custom-plugin) to write purely XPath-based rules. Assuming you are using SonarQube (and not SonarCloud), you can simply define new XPath-based rules using the template rule xml:S140 (or “xml:XPathCheck”). Note that the only constraint I know for sure is that you will need to use XPath 1.0. XPath 2.0 is not supported.

You will also be able to define different instances of this rules if you need to apply multiple XPath queries (this rule being a “template” rule). Please refer to the documentation (under “Rules Template”) for more details.

Regards,
Michael