xmlstarlet replace xml node value

≯℡__Kan透↙ 提交于 2019-12-06 10:37:22

问题


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



来源:https://stackoverflow.com/questions/46390426/xmlstarlet-replace-xml-node-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!