Search code examples
xpathpom.xmlxpath-1.0

XPath 1.0 get tag with dot in the attribute name


I want to get <sonar.exclusions>, <jacoco.line.min.coverage> and <jacoco.complexity.min.coverage> from the pom.xml

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>xxx.xxx.xxx/groupId>
<artifactId>yyyy</artifactId>
<version>zzzzz</version>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
    <maven-assembly-plugin.version>3.3.0</maven-assembly-plugin.version>
    <java.version>11</java.version>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    <jacoco.complexity.min.coverage>1.0</jacoco.complexity.min.coverage>
    <jacoco.line.min.coverage>1.0</jacoco.line.min.coverage>
    <sonar.exclusions>jjjjjj.jjjjj.jjjjj.Jjjj</sonar.exclusions>
</properties>

I don't know how get the value in the attributes with a dot in their in name in xPath 1.0.

Thanks.


Solution

  • This XPath will give it:

    "//*[local-name()='sonar.exclusions' or local-name()='jacoco.line.min.coverage' or local-name()='jacoco.complexity.min.coverage']"
    

    Tested on http://xpather.com/ The result is correct

    enter image description here