Force xmllint to ignore bad default xmlns
xmllint --xpath "/*[local-name() = 'project']/*[local-name() = 'parent']/*[local-name() = 'version']/text()" pom.xml
For a top level pom.xml:
xmllint --xpath "/*[local-name() = 'project']/*[local-name() = 'version']/text()" pom.xml
It ain't real pretty, but it avoids formatting assumptions and/or re-formatting the input pom.xml file.
If you need to strip off the "-SNAPSHOT" for some reason, pipe the result of the above through | sed -e "s|-SNAPSHOT||"
.
strip the namespace with sed
given in 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
</project>
this:
cat pom.xml | sed '2 s/xmlns=".*"//g' | xmllint --xpath '/project/modelVersion' -
returns this:
<modelVersion>4.0.0</modelVersion>
if you have funky formatting (like, the xmlns attributes are on their own lines), run it through the formatter first:
cat pom.xml | xmllint --format - | sed '2 s/xmlns=".*"//g' | xmllint --xpath '/project/modelVersion' -