微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

xmlstarlet 与命名空间属性替换

如何解决xmlstarlet 与命名空间属性替换

我无法用 xmlstarlet 替换属性

狗.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:rabbit="http://www.springframework.org/schema/rabbit"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/rabbit    http://www.springframework.org/schema/rabbit/spring-rabbit.xsd">
<rabbit:connection-factory id="mqConnectionFactory"
host="localhost"
port="9999" />
</beans>

已经尝试了以下多种变体:

xmlstarlet ed -N B="http://www.springframework.org/schema/beans" -N R="http://www.springframework.org/schema/rabbit" --update "/B/R:connection-factor/@host"  --value "myserver" dog.xml

我错过了什么?我已经尝试过 beans 和 B:beans for B 以及 R 的许多变体,但我认为没有选择正确的元素。

解决方法

使用完整的命名空间声明,

xmlstarlet ed \
    -N B="http://www.springframework.org/schema/beans" \
    -N rabbit="http://www.springframework.org/schema/rabbit" \
    --update '/B:beans/rabbit:connection-factory/@host' \
    --value "myserver" dog.xml

或者,使用 xmlstarlet 快捷方式,根据 user guide

xmlstarlet ed \
    -N rabbit="http://www.springframework.org/schema/rabbit" \
    --update '/_:beans/rabbit:connection-factory/@host' \
    --value "myserver" dog.xml

发现错别字:您的命令丢失 y 中的最后一个 connection-factory

,

以您的示例解决 failed to load external entity 问题的两种方法:

xmlstarlet edit --update "//@host" --value "myserver" file.xml

xmlstarlet edit --update "//*[local-name()='connection-factory']/@host" --value "myserver" file.xml

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。