# Custom Xpath Rule not working for Xaml

**URL:** <https://community.sonarsource.com/t/custom-xpath-rule-not-working-for-xaml/19363>\
**Category:** Writing rules\
**Tags:** xml\
**Created:** [January 29, 2020, 5:51am UTC](https://community.sonarsource.com/t/custom-xpath-rule-not-working-for-xaml/19363 "2020-01-29T05:51:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![vishnuvarthan](https://avatars.discourse-cdn.com/v4/letter/v/8e8cbc/32.png) [@vishnuvarthan](https://community.sonarsource.com/u/vishnuvarthan)\
**Post date:** [January 29, 2020, 5:51am UTC](https://community.sonarsource.com/t/custom-xpath-rule-not-working-for-xaml/19363/1 "2020-01-29T05:51:05Z")

</div>

HI

I am trying to write a custom rule for the below xaml file . The rule works properly in external tools available to validate Xpath .However , it is not flagging in SonarQube. My xaml file

[New Text Document.txt](https://community.sonarsource.com/uploads/short-url/enuP3omqTeobIHR40Y3VB5DIvUx.txt) (5.4 KB)  
xpath query : count(Activity/Sequence//ui:SendOutlookMail/ui:SendOutlookMail.Files/scg:List/InArgument[not(contains(text(),"["))]) \> 0

Need help

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [January 29, 2020, 7:40am UTC](https://community.sonarsource.com/t/custom-xpath-rule-not-working-for-xaml/19363/2 "2020-01-29T07:40:45Z")

</div>

Hi,

Welcome to the community!

The custom XPath rule templates only support XPath 1.0. Is that what you used?

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![vishnuvarthan](https://avatars.discourse-cdn.com/v4/letter/v/8e8cbc/32.png) [@vishnuvarthan](https://community.sonarsource.com/u/vishnuvarthan)\
**Post date:** [January 29, 2020, 7:51am UTC](https://community.sonarsource.com/t/custom-xpath-rule-not-working-for-xaml/19363/3 "2020-01-29T07:51:43Z")

</div>

Yes, the rule is made up of xpath 1.0 only . It works in other sites but not with Sonarqube

---

<div class="post-metadata">

**Author:** ![Lena](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/lena/32/66719_2.png) [@Lena](https://community.sonarsource.com/u/Lena)\
**Post date:** [January 31, 2020, 9:31am UTC](https://community.sonarsource.com/t/custom-xpath-rule-not-working-for-xaml/19363/4 "2020-01-31T09:31:28Z")

</div>

Hi,

Your XPath expression returns boolean. It should return nodes of the XML in order to rule to report something.

---

<div class="post-metadata">

**Author:** ![vishnuvarthan](https://avatars.discourse-cdn.com/v4/letter/v/8e8cbc/32.png) [@vishnuvarthan](https://community.sonarsource.com/u/vishnuvarthan)\
**Post date:** [January 31, 2020, 9:50am UTC](https://community.sonarsource.com/t/custom-xpath-rule-not-working-for-xaml/19363/5 "2020-01-31T09:50:46Z")

</div>

Hi Elena

Thanks for the reply. We are creating custom rules,

we have other rules configured in the same way , i.e it returns Boolean . If a Boolean value is True , it will show that particular rule in Issues.

---

<div class="post-metadata">

**Author:** ![Lena](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/lena/32/66719_2.png) [@Lena](https://community.sonarsource.com/u/Lena)\
**Post date:** [January 31, 2020, 1:23pm UTC](https://community.sonarsource.com/t/custom-xpath-rule-not-working-for-xaml/19363/6 "2020-01-31T13:23:18Z")

</div>

Removing namespaces from the xpath fixed the problem:  
`count(Activity/Sequence/SendOutlookMail/SendOutlookMail.Files/List/InArgument[not(contains(text(),"["))]) > 0`

Not sure why it does not work with the namespaces.

---

<div class="post-metadata">

**Author:** ![vishnuvarthan](https://avatars.discourse-cdn.com/v4/letter/v/8e8cbc/32.png) [@vishnuvarthan](https://community.sonarsource.com/u/vishnuvarthan)\
**Post date:** [January 31, 2020, 1:41pm UTC](https://community.sonarsource.com/t/custom-xpath-rule-not-working-for-xaml/19363/7 "2020-01-31T13:41:59Z")

</div>

Thanks a lot, I will check and confirm it back to u 🙂

---

<div class="post-metadata">

**Author:** ![vishnuvarthan](https://avatars.discourse-cdn.com/v4/letter/v/8e8cbc/32.png) [@vishnuvarthan](https://community.sonarsource.com/u/vishnuvarthan)\
**Post date:** [February 1, 2020, 1:45pm UTC](https://community.sonarsource.com/t/custom-xpath-rule-not-working-for-xaml/19363/8 "2020-02-01T13:45:50Z")

</div>

It Works Elena 🙂 Thanks a lot …!
