2017-09-24 106 views
1

我想知道如何使用xmlstarlet添加新行。xmlstarlet追加並插入新行值

我的目標是在job/input/file_input/uri後面添加一個<audio>track_01</audio>

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

我如何可以插入使用下面的代碼新的生產線?

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 

非常感謝您

回答

0

我建議所需的節點/元素後追加(--append)與名音頻(--name "audio")和價值(--value "track_01")的新元素(--type elem):

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 

如果要編輯inplace文件,請添加選項-L


參見:xmlstarlet edit --help

+1

太感謝你了!盡你所能幫助我。 – jojo

+0

沒問題。如果我的回答有幫助,請投票。謝謝。 – Cyrus