xmlstarlet替换xml节点值

时间:2017-09-24 13:14:21

标签: xmlstarlet

我是使用xmlstarlet的新手。我想知道如何使用xmlstarlet更改xml节点的值。

我试了一下。 xmlstarlet ed --inplace -u'/ file_input / uri''string(“s3:// my_source”)'template.xml>的Output.xml

不起作用。

我的预期输出为 s3:// my_source s3:// mydestination 。我想更改 source_path destination_path 节点。

<?xml version="1.0" encoding="UTF-8"?>
<job version="2.10.8">
  <input>
    <deblock_enable>Auto</deblock_enable>
    <deblock_strength>0</deblock_strength>
    <no_psi>false</no_psi>
    <order>1</order>
    <timecode_source>zerobased</timecode_source>
    <file_input>
      <certificate_file nil="true"/>
      <password>upass</password>
      <uri>source_path</uri>
      <username>uname</username>
    </file_input>
    <file_group_settings>
      <rollover_interval nil="true"/>
      <destination>
        <password>upass</password>
        <username>uname</username>
        <uri>destination_path</uri>
      </destination>
    </file_group_settings>
  </input>
</job>

非常感谢

1 个答案:

答案 0 :(得分:3)

使用xmlstarlet:

xmlstarlet edit \
           --update "//job/input/file_input/uri" \
           --value 's3://my_source' \
           --update "//job/input/file_group_settings/destination/uri" \
           --value 's3://mydestination' file.xml

如果要在场内编辑file.xml,请添加选项-L

请参阅:xmlstarlet edit --help