XML xpath rule not triggered on sonarqube 7.7

Must-share information (formatted with Markdown):

  • SonarQube 7.7 Community, XML Plugin 2.0.1
  • i created a custom xpath rule name “SOMERULE” with this expression: //ATTRIBUTE[@tokenValue=‘lang’]
  • I activated this rule in a Quality Profile
  • my project contains the .xml file mentioned below (which I want to have evaluated and which should fail)
  • running it using mvn sonar:sonar
  • i go to the project tab in the web client
  • the rule is not triggerred
  • I also see no evidence in the mvn logs that it was triggered (however the XML profile has been run)

Question: How do I know that my rule //ATTRIBUTE[@tokenValue=‘lang’] was even evaluated? Did it even run?

<?xml version="1.0" encoding="ISO-8859-1"?>
<title lang="eng">Harry Potter</title>
<title lang="eng">Learning XML</title>

Hello @christiaan,

First thing, be sure that your xml file is included in the sources. By default, the maven scanner only includes pom.xml for xml files. You can do so, by using, for instance, the sonar.sources property.

Trying to reproduce your case, I placed a xml file in the src/main/resources and needed to setup my sources as following to catch it (don’t forget to force inclusion of the pom as well, or you will lose it):

    <!-- ... -->

Now, regarding your XML XPath rule, what node from the XML file are you trying to target?

I tried using directly your XPath rule //ATTRIBUTE[@tokenValue='lang'] against your example with a online XPath tester (https://www.freeformatter.com/xpath-tester.html) and the rule does not match any node!

However, I was able to raise two issues with the following expression: //title[@lang='eng'].

By the way, copy-pasting your expression, I realized you are not using the standard single-quote character.


1 Like


Thank you so much for your response. I managed to get it to work (prior to your response) by adding the path to the folder which contains the url like this on the (extended) xpath rule like this: **/*.xml

But i understand now that this can be done on the pom file as well, and thus be made generic for all rules.

Thank you again!


1 Like