如何使用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
原操作问题说明
- 未通过链式操作在新增元素后追加属性配置
- 未使用
amq:app[last()]精准定位刚插入的新元素,该语法只会匹配当前web节点下最后一个app元素,也就是你刚新增的空元素,完全不会修改之前已存在的其他app元素 - 新增元素时指定名称为
amq:app可保证新元素和父节点属于同一命名空间,避免ActiveMQ读取配置时识别不到新增节点
内容的提问来源于stack exchange,提问作者mal
相关产品推荐
相关产品推荐

