user2528256
user2528256

Reputation: 63

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?

Upvotes: 6

Views: 1218

Answers (1)

kjhughes
kjhughes

Reputation: 111591

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

Reference links

Upvotes: 11

Related Questions