首页 > 解决方案 > 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!

标签: sedxmlstarlet

解决方案


编辑:由于 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

推荐阅读