与 XPath 一起使用时如何在 xmlstarlet 更新命令中正确添加 xml 命名空间
How to proper add xml namespace in an xmlstarlet update command when along used with XPath
我的 xmlstarlet 命令有什么问题?
如果在父元素
下满足以下约束条件,我正在尝试更新我的 pom.xml 的版本元素
groupId == com.cisco.aems
和
版本 == 3.700.11-SNAPSHOT
xml 命名空间概念使我对 xmlstarlet 语法的理解变得复杂,任何帮助解决我的 xmlstarlet 问题的帮助将不胜感激。
谢谢:-)
我尝试了以下命令的变体
xmlstarlet ed -N a="http://maven.apache.org/POM/4.0.0" -u "/a:groupId[.='com.cisco.aems' and following
-sibling::version[1] = '3.700.11-SNAPSHOT']/a:following-sibling::version[1]" -x "concat(.,'-done')" pom_sandbox_nam.xml
要么我得到一个无效的表达式错误,要么什么都没有但我没有得到预期的结果
样本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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>avc-utils</artifactId>
<parent>
<groupId>com.cisco.aems</groupId>
<artifactId>aems_parent_pom</artifactId>
<version>3.700.11-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
</project>
预计
<?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>
<artifactId>avc-utils</artifactId>
<parent>
<groupId>com.cisco.aems</groupId>
<artifactId>aems_parent_pom</artifactId>
<version>3.700.11-SNAPSHOT-done</version>
<relativePath>../../pom.xml</relativePath>
</parent>
</project>
实际结果
<?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>
<artifactId>avc-utils</artifactId>
<parent>
<groupId>com.cisco.aems</groupId>
<artifactId>aems_parent_pom</artifactId>
<version>3.700.11-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
</project>
使用以下命令:
xmlstarlet ed -N a="http://maven.apache.org/POM/4.0.0" -u "/a:project/a:parent/a:groupId[.='com.cisco.aems' and following-sibling::a:version[1] = '3.700.11-SNAPSHOT']/following-sibling::a:version[1]" -x "concat(.,'-done')" pom_sandbox_nam.xml
结果如下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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>avc-utils</artifactId>
<parent>
<groupId>com.cisco.aems</groupId>
<artifactId>aems_parent_pom</artifactId>
<version>3.700.11-SNAPSHOT-done</version>
<relativePath>../../pom.xml</relativePath>
</parent>
</project>
您没有指定要更改的元素的完整路径,也没有指定适当的命名空间。
我的 xmlstarlet 命令有什么问题?
如果在父元素
下满足以下约束条件,我正在尝试更新我的 pom.xml 的版本元素
groupId == com.cisco.aems
和
版本 == 3.700.11-SNAPSHOT
xml 命名空间概念使我对 xmlstarlet 语法的理解变得复杂,任何帮助解决我的 xmlstarlet 问题的帮助将不胜感激。 谢谢:-)
我尝试了以下命令的变体
xmlstarlet ed -N a="http://maven.apache.org/POM/4.0.0" -u "/a:groupId[.='com.cisco.aems' and following
-sibling::version[1] = '3.700.11-SNAPSHOT']/a:following-sibling::version[1]" -x "concat(.,'-done')" pom_sandbox_nam.xml
要么我得到一个无效的表达式错误,要么什么都没有但我没有得到预期的结果
样本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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>avc-utils</artifactId>
<parent>
<groupId>com.cisco.aems</groupId>
<artifactId>aems_parent_pom</artifactId>
<version>3.700.11-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
</project>
预计
<?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>
<artifactId>avc-utils</artifactId>
<parent>
<groupId>com.cisco.aems</groupId>
<artifactId>aems_parent_pom</artifactId>
<version>3.700.11-SNAPSHOT-done</version>
<relativePath>../../pom.xml</relativePath>
</parent>
</project>
实际结果
<?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>
<artifactId>avc-utils</artifactId>
<parent>
<groupId>com.cisco.aems</groupId>
<artifactId>aems_parent_pom</artifactId>
<version>3.700.11-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
</project>
使用以下命令:
xmlstarlet ed -N a="http://maven.apache.org/POM/4.0.0" -u "/a:project/a:parent/a:groupId[.='com.cisco.aems' and following-sibling::a:version[1] = '3.700.11-SNAPSHOT']/following-sibling::a:version[1]" -x "concat(.,'-done')" pom_sandbox_nam.xml
结果如下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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>avc-utils</artifactId>
<parent>
<groupId>com.cisco.aems</groupId>
<artifactId>aems_parent_pom</artifactId>
<version>3.700.11-SNAPSHOT-done</version>
<relativePath>../../pom.xml</relativePath>
</parent>
</project>
您没有指定要更改的元素的完整路径,也没有指定适当的命名空间。