xml - 基于 shell 中的两个父子值添加 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
推荐阅读
- javascript - 如何在 django 模板中分离 javascript 函数
- scala - 如何在集成测试中执行此控制器操作代码?
- reportportal - 报告门户需要网络驱动程序?
- python - 如何添加空白命令?(Discord.py)
- javascript - GraphQL 突变的响应应该是什么?
- oracle - 在哪里下载适用于 Macbook 的 Oracle SQL*Loader?
- c# - c# - 合并两个列表
使用列表中的时间戳 - r - ggplot2 facet grid 有条件的 facet 和整洁的评估
- ios - 无法使用 Facebook 4.37.0 从 iOS 打开 Messenger
- c++ - 如何在调试器中进行代码路径分析?