xmlstarlet append and insert new line value

允我心安 提交于 2019-12-30 11:35:18

问题


I'd like to know how to add a new line using xmlstarlet.

My aim is to add a <audio>track_01</audio> after job/input/file_input/uri.

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

How can I insert new line using the below code?

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

Thank you very much


回答1:


I suggest to append (--append) after the desired node/element a new element (--type elem) with name audio (--name "audio") and value (--value "track_01"):

xmlstarlet edit \
           --update "//job/input/file_input/uri" \
           --value 's3://my_source' \
           --update "//job/input/file_group_settings/destination/uri" \
           --value 's3://mydestination' \
           --append "//job/input/file_input/uri" \
           --type elem --name "audio" --value "track_01" file.xml

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


See: xmlstarlet edit --help



来源:https://stackoverflow.com/questions/46392564/xmlstarlet-append-and-insert-new-line-value

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