I'm having issue extracting the version number from POM. Can someone help me with it ?
POM.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<artifactId>watcher</artifactId>
<version>0.0.1-SNAPSHOT</version>
<groupId>com.test.file</groupId>
<name>file-watcher</name>
<packaging>jar</packaging>
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<relativePath/>
<version>2.6.1</version>
</parent>
</project>
XPATH Expression:
//project/version/text()
Error: This is returning no match found
CodePudding user response:
Your elements are in a default namespace. So try a namespace-agnostic XPath-1.0 expression like the following:
/*[local-name()='project']/*[local-name()='version']/text()
Its output is
0.0.1-SNAPSHOT
as desired.
CodePudding user response:
Your XPath here is correct, it should return 0.0.1-SNAPSHOT
It can be simulated on XPath simulators like
So it's quite clear your problem is not with the XPath expression while with what you doing with it.