Help with xpath for xml template rules


(Marcel Walliser) #1


i’m new to sonar and xpath and i have kind of the same problem.

my XML broken down looks like this

<?xml version="1.0" encoding="utf-8"?>

i want to write a custom rule which checks if is false or not and want to have an error if it is not false.

I tried it with this


but i dont get an error message.


In the meantime i found the SSLR Toolkit and got some working XPath for my need, but Sonar still doesnt give me an errormessage and i dont know why.

This is my XPath:

//ELEMENT[./S_TAG/NAME/@tokenValue='Private' and ./CONTENT/CHAR_DATA/TOKEN/@tokenValue='False']

and this is my Syntax Tree

Validating XML documents
(Pierre-Yves Nicolas) #2

Your original XPath expression looks good to me. Except that, given the != operator, it raises issues only when the content of the Private tag is not False. I set up the following expression and it raised an issue on your code example: