How to use XML namespaces with xmlstarlet XPaths?

99封情书 提交于 2019-12-07 09:31:47

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/29347088/how-to-use-xml-namespaces-with-xmlstarlet-xpaths

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!