Help with xpath for xml template rules

xml
template_rule

(Marcel Walliser) #1

Hi,

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"?>
        <Project>
                <ItemGroup>
                       <ProjectReference>
                            <Private>False</Private>
                       </ProjectReference>
                </ItemGroup>
        </Project>

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

/Project/ItemGroup/ProjectReference/Private[text()!='False']

but i dont get an error message.

--------------------------------------------------EDIT---------------------------------------------------------------------

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:

/Project/ItemGroup/ProjectReference/Private[text()='False']