如何使用xmlstarlet将新的子元素添加到bootstrap.xml文件中的web元素



如何使用xmlstarlet:将新的子元素<app url="metrics" war="metrics.war"/>添加到下面xml文件中的web元素

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~     http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<broker xmlns="http://activemq.org/schema">
<jaas-security domain="activemq"/>
<!-- artemis.URI.instance is parsed from artemis.instance by the CLI startup.
This is to avoid situations where you could have spaces or special characters on this URI -->
<server configuration="file:/var/lib/./artemisBroker/etc//broker.xml"/>
<!-- The web server is only bound to localhost by default -->
<web bind="http://0.0.0.0:8161" path="web">
<app url="activemq-branding" war="activemq-branding.war"/>
<app url="artemis-plugin" war="artemis-plugin.war"/>
<app url="console" war="console.war"/>
</web>
</broker>

这是在docker图像中,我提取ActiveMQ并进行设置,然后我想添加一个Prometheus度量插件。我将所需的jar/war文件复制到正确的文件夹中,但现在我需要修改bootstrap.xml以引用war文件。

我可以在Dockerfile中看到,xmlstartlet已被用于修改bind属性,如下所示:

RUN cd /var/lib/artemisBroker/etc && 
xmlstarlet ed -L -N amq="http://activemq.org/schema" 
-u "/amq:broker/amq:web/@bind" 
-v "http://0.0.0.0:8161" bootstrap.xml

但是我不知道如何添加一个新元素
我发现了这个问题,这有助于澄清一些事情,但我仍然做错了什么
经过一番尝试和错误,我得出了以下结论:

xmlstarlet ed -L -N amq="http://activemq.org/schema"
-s "amq:broker/amq:web" 
-t elem -n "app"  bootstrap.xml

它似乎运行得很好,并添加了一个<app />元素,但我不知道如何在不覆盖文件中其他<app />元素的情况下添加我想要的属性
我做错了什么?

这样试试:

xmlstarlet ed --subnode "//web" --type elem -n app --insert  "// web //app[3]"  --type attr --name "url" --value "metrics" --insert  "// web //app[3]" --type attr --name "war" --value "metrics.war" bootstrap.xml

看看它是否有效。