Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use XML namespaces with xmlstarlet XPaths?

at the moment I am struggeling editing a XML file. When I write the command

xml ed -u "/project/version" -v "2.7.13-NEW-SNAPSHOT" pom.xml > ./pom_new.xml

it writes the new xml file, but when I open the file nothings changed in it.

Heres a part of the given xml, i want to edit:

<?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>com.groupID.test</groupId>
    <artifactId>test-api-parent-pom</artifactId>
    <version>2.7.13-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>test-api-parent-pom</name>
    ...
    ...
</project>

Any ideas on that?

like image 503
user2528256 Avatar asked Feb 10 '23 13:02

user2528256


1 Answers

Your xmlstarlet command will work if you take account of your document's namespace using -N p=http://maven.apache.org/POM/4.0.0:

xml ed -N p=http://maven.apache.org/POM/4.0.0 -u "/p:project/p:version" -v "2.7.13-NEW-SNAPSHOT" pom.xml > ./pom_new.xml
like image 97
kjhughes Avatar answered Feb 24 '23 14:02

kjhughes