xmlstarlet 追加并插入新行值 [英] xmlstarlet append and insert new line value

查看:35
本文介绍了xmlstarlet 追加并插入新行值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用 xmlstarlet 添加新行.

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

我的目标是在 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

非常感谢

推荐答案

我建议在想要的节点/元素之后追加 (--append) 一个新元素 (--type elem) 带有名称音频 (--name "audio") 和值 (--value "track_01"):

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

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

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

参见:xmlstarlet edit --help

这篇关于xmlstarlet 追加并插入新行值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆