# XPATH custom rules

**URL:** <https://community.sonarsource.com/t/xpath-custom-rules/14485>\
**Category:** SonarQube Server / Community Build\
**Tags:** xml\
**Created:** [September 19, 2019, 2:03pm UTC](https://community.sonarsource.com/t/xpath-custom-rules/14485 "2019-09-19T14:03:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![darcode](https://avatars.discourse-cdn.com/v4/letter/d/da6949/32.png) [@darcode](https://community.sonarsource.com/u/darcode)\
**Post date:** [September 19, 2019, 2:03pm UTC](https://community.sonarsource.com/t/xpath-custom-rules/14485/1 "2019-09-19T14:03:14Z")

</div>

Hi,  
I’m trying to create an XPATH rule for xml files but when I run sonar-scanner it does not seem that the custom rule is evaluated.  
I’ve created a simple XML fle and a simple XPATH and a quality gate and activated that custom rule with the quality gate.  
The XPATH expression is the sample given:  
//td[@nowrap]

And the XML file is containing that.

I’ve installed sonarqube 7.9.1 on postgreSQL and using sonar-scanner-4.0.0.1744-windows.

Is there a tutorial step by step which can help me?

---

<div class="post-metadata">

**Author:** ![pynicolas](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/pynicolas/32/675_2.png) [@pynicolas](https://community.sonarsource.com/u/pynicolas)\
**Post date:** [September 23, 2019, 11:29am UTC](https://community.sonarsource.com/t/xpath-custom-rules/14485/2 "2019-09-23T11:29:38Z")

</div>

What’s the content of the XML file?  
What’s the name of the XML file?  
Did you set the following parameters on the XPath rule you created?

- `filePattern`
- `message`

Do you see something special in the logs of the analysis?

---

<div class="post-metadata">

**Author:** ![aloksrivastava269](https://avatars.discourse-cdn.com/v4/letter/a/bc8723/32.png) [@aloksrivastava269](https://community.sonarsource.com/u/aloksrivastava269)\
**Post date:** [October 21, 2019, 7:37am UTC](https://community.sonarsource.com/t/xpath-custom-rules/14485/3 "2019-10-21T07:37:55Z")

</div>

Hi Pierre,

I am also facing same kind of issue, I am trying to validate if a file name weblogic.xml, If the file doesn’t have declared the attribute names as page-check-seconds then report violation.

**filePattern** : weblogic.xml  
The XPath query = not(//jsp-descriptor/jsp-param/param-name[text()=‘page-check-seconds’])  
Message : Page check seconds are not mentioned

**File content:**

\<?xml version="1.0" encoding="UTF-8"?\> keepgenerated true page-check-sec true 

But I am not able to see any sonar violation , I an scanning file using sonar-scanner. I am using soanrqube 7.2.

PS: I am novice to SonarQube.

---

<div class="post-metadata">

**Author:** ![pynicolas](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/pynicolas/32/675_2.png) [@pynicolas](https://community.sonarsource.com/u/pynicolas)\
**Post date:** [October 31, 2019, 2:13pm UTC](https://community.sonarsource.com/t/xpath-custom-rules/14485/4 "2019-10-31T14:13:40Z")

</div>

@aloksrivastava269 see the answer on the thread which you created:

> [@Custom XPATH rule is not working](https://community.sonarsource.com/t/custom-xpath-rule-is-not-working/15716/6):
>
> To raise an XPath issue on a file, the XPath expression has to return a boolean. As your last expression is the result of the concat function, it returns a string. I suggest using: count(//jsp-descriptor/jsp-param/param-name[text()='page-check-seconds']) = 0 One more thing: if the pattern of the XPath rule is weblogic.xml, it will only look for a file named weblogic.xml at the root of the project. You may want to set the pattern to \*\*/weblogic.xml to scan all files named weblogic.xml.
