Xpath expression for blocking missing <scope> node

  • 9.5 community
  • block an xml (a pom) that doesn’t contain a certain tag
  • via xpath template

hello,

i would like to create an xml template to match this situation

    <dependency>
        <groupId>blabla</groupId>
        <artifactId>fabrickcore-spring-boot-starter-test</artifactId>
    </dependency>

the “factor” it’s the missing of tag

on this website i try

the following xpath expression

//dependency/artifactId/text()[. = 'fabrickcore-spring-boot-starter-test']/../..[not(scope)]

and this match (correct)

    <dependency>
        <groupId>blabla</groupId>
        <artifactId>fabrickcore-spring-boot-starter-test</artifactId>
    </dependency>

and don’t match (correct)

    <dependency>
        <groupId>blabla</groupId>
        <artifactId>fabrickcore-spring-boot-starter-test</artifactId>
        <scope>blabla</scope>
    </dependency>

so from the tester point of view my xpath expression it’s working.

on sonar i am not able to make it work, and i can’t get any debug information about that.

i think (but i am not sure) it’s the last part that break ie: [not(scope)] because if i do a rule with

//dependency/artifactId/text()[. = 'fabrickcore-spring-boot-starter-test']/../..

the rule work and match the element (that’s of course not the scenario i need, but i did try to break out a bit the expression)

can someone advice on that?

thanks for the support!

ps: not sure why but the code display 3 dots, while i use 2 dots in xpath :smiley:

Hello @ramarro123,

Could you let me know whether you are using xpath 1 or 2 please?

Best.