【问题标题】:xmlstarlet append and insert new line valuexmlstarlet 追加并插入新行值
【发布时间】:2018-01-03 18:20:40
【问题描述】:

我想知道如何使用 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

非常感谢

【问题讨论】:

    标签: xml xmlstarlet


    【解决方案1】:

    我建议在所需的节点/元素之后附加(--append)一个新元素(--type elem),名称为音频(--name "audio")和值(--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
    

    如果要就地编辑 file.xml,请添加选项 -L


    见:xmlstarlet edit --help

    【讨论】:

      猜你喜欢
      • 2019-09-15
      • 1970-01-01
      • 1970-01-01
      • 2022-06-17
      • 2011-12-08
      • 1970-01-01
      • 1970-01-01
      • 2015-02-25
      • 1970-01-01
      相关资源
      最近更新 更多