问题
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