根据 shell 中的两个父子值添加 XML 节点
Add XML node based on two of parents child values in the shell
我该如何更改:
...
<dependencies>
...
<dependency>
<groupId>xyz</groupId>
<artifactId>abc</artifactId>
</dependency>
...
</dependencies>
...
到那个:
...
<dependencies>
...
<dependency>
<groupId>xyz</groupId>
<artifactId>abc</artifactId>
<scope>system</scope>
<systemPath>/.../src/main/.../some.jar</systemPath>
</dependency>
...
</dependencies>
...
基于“/dependencies/dependency/groupId”和“/dependencies/dependency/artifactId”的值
在 bash(由 xmlstarlet,...)?
更新
显然这似乎还不够清楚。
所以:代码必须找到 groupId==xyz 和 artifactId==abc 的依赖关系,然后(并且只有这样)将两个 now 节点添加到 groupId 和 artifactId 节点的父节点。
试试这样的东西:
xmlstarlet ed \
--subnode "//dependency[//artifactId[./text()='abc']][//groupId[./text()='xyz']]" --type elem -n scope -v "system" \
--subnode "//dependency[//artifactId[./text()='abc']][//groupId[./text()='xyz']]" --type elem -n systemPath -v "some.jar" \
file.xml
在@Jack Fleeting 和来自@uk4sx (XMLStarlet does not select anything) 的 post 的帮助下 - 必须设置命名空间 - 我终于得到了它 运行ning 这样的 (在 Dockerfile 中 运行):
RUN xmlstarlet ed -L -N my=http://maven.apache.org/POM/4.0.0 \
--subnode "//my:dependencies/my:dependency[my:artifactId[./text()='abc']][my:groupId[./text()='xyz']]" \
--type elem -n scope -v "system" \
--subnode "//my:dependencies/my:dependency[my:artifactId[./text()='abc']][my:groupId[./text()='xyz']]" \
--type elem -n systemPath -v "\.../src/main/.../some.jar" \
./pom.xml
我该如何更改:
...
<dependencies>
...
<dependency>
<groupId>xyz</groupId>
<artifactId>abc</artifactId>
</dependency>
...
</dependencies>
...
到那个:
...
<dependencies>
...
<dependency>
<groupId>xyz</groupId>
<artifactId>abc</artifactId>
<scope>system</scope>
<systemPath>/.../src/main/.../some.jar</systemPath>
</dependency>
...
</dependencies>
...
基于“/dependencies/dependency/groupId”和“/dependencies/dependency/artifactId”的值
在 bash(由 xmlstarlet,...)?
更新
显然这似乎还不够清楚。 所以:代码必须找到 groupId==xyz 和 artifactId==abc 的依赖关系,然后(并且只有这样)将两个 now 节点添加到 groupId 和 artifactId 节点的父节点。
试试这样的东西:
xmlstarlet ed \
--subnode "//dependency[//artifactId[./text()='abc']][//groupId[./text()='xyz']]" --type elem -n scope -v "system" \
--subnode "//dependency[//artifactId[./text()='abc']][//groupId[./text()='xyz']]" --type elem -n systemPath -v "some.jar" \
file.xml
在@Jack Fleeting 和来自@uk4sx (XMLStarlet does not select anything) 的 post 的帮助下 - 必须设置命名空间 - 我终于得到了它 运行ning 这样的 (在 Dockerfile 中 运行):
RUN xmlstarlet ed -L -N my=http://maven.apache.org/POM/4.0.0 \
--subnode "//my:dependencies/my:dependency[my:artifactId[./text()='abc']][my:groupId[./text()='xyz']]" \
--type elem -n scope -v "system" \
--subnode "//my:dependencies/my:dependency[my:artifactId[./text()='abc']][my:groupId[./text()='xyz']]" \
--type elem -n systemPath -v "\.../src/main/.../some.jar" \
./pom.xml