2017-09-24 149 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