You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用xmlstarlet为bootstrap.xml的web元素添加带属性的app子节点

正确实现方案

你此前的操作已经完成了新增空元素的核心步骤,仅缺少链式添加属性的操作,且需注意命名空间匹配和新元素的精准定位,避免影响已有<app>元素。

完整命令如下:

xmlstarlet ed -L -N amq="http://activemq.org/schema" \
  # 给web节点新增amq命名空间下的app子元素
  --subnode "/amq:broker/amq:web" --type elem -n amq:app -v "" \
  # 为刚新增的最后一个app元素添加url属性
  --insert "/amq:broker/amq:web/amq:app[last()]" --type attr -n url -v "metrics" \
  # 为刚新增的最后一个app元素添加war属性
  --insert "/amq:broker/amq:web/amq:app[last()]" --type attr -n war -v "metrics.war" \
  bootstrap.xml

Dockerfile 集成写法:

RUN cd /var/lib/artemisBroker/etc && \
  xmlstarlet ed -L -N amq="http://activemq.org/schema" \
    --subnode "/amq:broker/amq:web" --type elem -n amq:app -v "" \
    --insert "/amq:broker/amq:web/amq:app[last()]" --type attr -n url -v "metrics" \
    --insert "/amq:broker/amq:web/amq:app[last()]" --type attr -n war -v "metrics.war" \
    bootstrap.xml

原操作问题说明

  1. 未通过链式操作在新增元素后追加属性配置
  2. 未使用amq:app[last()]精准定位刚插入的新元素,该语法只会匹配当前web节点下最后一个app元素,也就是你刚新增的空元素,完全不会修改之前已存在的其他app元素
  3. 新增元素时指定名称为amq:app可保证新元素和父节点属于同一命名空间,避免ActiveMQ读取配置时识别不到新增节点

内容的提问来源于stack exchange,提问作者mal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 11:54:04