【问题标题】:xmlstarlet with namespaces attribute replacement带有命名空间属性替换的 xmlstarlet
【发布时间】:2021-07-28 08:00:43
【问题描述】:

我不能用 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 的许多变体,但我认为没有选择正确的元素。

【问题讨论】:

    标签: namespaces xml-namespaces xmlstarlet


    【解决方案1】:

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

    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
    

    找出错字:您的命令丢失 connection-factory 中的最后一个 y

    【讨论】:

      【解决方案2】:

      以您的示例解决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
      

      【讨论】:

      • 我仍然想知道完整路径的方法,但这解决了我的问题。
      猜你喜欢
      • 1970-01-01
      • 2013-11-02
      • 1970-01-01
      • 2018-12-20
      • 2013-06-17
      • 2011-05-09
      • 2016-10-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多