如何在xmlstarlet XPath中使用XML名称空间? [英] How to use XML namespaces with xmlstarlet XPaths?

查看:57
本文介绍了如何在xmlstarlet XPath中使用XML名称空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在努力编辑XML文件。当我编写命令

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

它会写入新的xml文件,但是当我打开该文件时,内容并没有改变

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

此处是给定xml的一部分,我要编辑:

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>

有什么想法吗?

推荐答案

如果使用 -N p = http://maven.apache.org/POM/4.0.0 考虑文档的名称空间,则xmlstarlet命令将起作用。 code>:

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

这篇关于如何在xmlstarlet XPath中使用XML名称空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆