-->

xmlstarlet replace xml node value

2019-04-13 17:58发布

问题:

I'm new using xmlstarlet. I'd like to know how to change the value of xml node using xmlstarlet.

I tried something. xmlstarlet ed --inplace -u '/file_input/uri' 'string("s3://my_source")' template.xml > output.xml

doesn't work.

My expected output as s3://my_source and s3://mydestination. I'd like to change source_path and destination_path node.

<?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>

Thank you very much

回答1:

With 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

If you want to edit file.xml inplace, add option -L.


See: xmlstarlet edit --help



标签: xmlstarlet