sed - how do edit complex xml file by sed
问题描述
this is the structure of xml file:
<test.file>
<set name="parameter1" serializeAs="String">
<value>True</value>
</set>
<set name="parameter2" serializeAs="String">
<value>True</value>
</set>
</test.file>
I want to edit value from True to False for Parameter2 when I use this command: xmlstarlet ed -u //test.\file/set/value -v False filename It is updating both value from True to False. How can I control to edit the value only for name="parameter2"?
Thank u!
解决方案
编辑:由于 OP 要求对特定标签的值进行更改,因此根据它更改了代码。
xmlstarlet ed -u "//test.file/set[@name='parameter2']/value" -v "false" Input_file.xml
以下xmlstarlet
命令可能会对您有所帮助。
xmlstarlet ed -u "/test.file/set/value" -v "false" Input_file.xml
要对 xml 文件本身进行就地更新,请使用以下内容。
xmlstarlet ed -L -u "/test.file/set/value" -v "false" Input_file.xml
推荐阅读
- bash - How to use SSH access via Bitbucket pipeline for deployment
- heroku - Stripe webhook error 400 bad request when using Heroku web address
- python - 从另一个文件调用 Tkinter 对象
- javascript - How to set a Date value to an object's value that could be undefined in Javascript
- javascript - 如何使用 filesaver.js 和 canvas-toBlob.js 防止文件保存后页面刷新
- java - 有没有办法在 Java 的同一行提出问题并获得输入?
- haskell - 检查列表头是否可以除以列表的第二个元素的函数
- swiftui - Picker View 数据消失太快
- javascript - 如何将具有应用输入值的html DOM元素存储为字符串
- python - 在 Travis CI 中构建 Python 项目失败,消息不明确