xmlstarlet 更新一个属性 [英] xmlstarlet update an attribute
本文介绍了xmlstarlet 更新一个属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个处理 xml 文件的脚本.我想用 xmlstarlet 更新这个 xml 文件中的属性值,但它不起作用.
I'm working on a script which deals with an xml file. I'd like to update an attribute value in this xml file with xmlstarlet but it doesn't work.
这里是 xml 文件的示例:
Here is a sample of the xml file:
<?xml version="1.0" encoding="UTF-8"?>
<channel name="xfce4-keyboard-shortcuts" version="1.0">
<property name="commands" type="empty">
<property name="default" type="empty">
<property name="<Alt>F2" type="empty"/>
<property name="<Control><Alt>Delete" type="empty"/>
<property name="XF86Display" type="string" value="xrandr --output LVDS --auto --output VGA-0 --mode 1680x1050_60.00 --right-of LVDS"/>
</property>
<property name="custom" type="empty">
<property name="<Alt>F2" type="string" value="xfrun4"/>
<property name="<Control><Alt>Delete" type="string" value="xflock4"/>
<property name="XF86Display" type="string" value="xrandr --output LVDS --auto --output VGA-0 --mode 1680x1050_60.00 --right-of LVDS"/>
<property name="override" type="bool" value="true"/>
</property>
</property>
</channel>
这是更新自定义属性节点中名为XF86Display"的属性的命令.
And here is the command to update the property with the name "XF86Display" in the custom property node.
xmlstarlet edit \
--update "/xml/channel[@name=xfce4-keyboard-shortcuts]/property[@name=commands]/property[@name=custom]/property[@name=XF86Display]/@value" \
--value "test" xfce4-keyboard-shortcuts.xml
此输出与输入完全相同...
This output is strictly the same to the input...
谢谢
推荐答案
这对我有用(根是
; 引用的属性值):
This works for me (the root is <channel>
; attribute values quoted):
xmlstarlet edit \
--update "/channel[@name='xfce4-keyboard-shortcuts']/property[@name='commands']/property[@name='custom']/property[@name='XF86Display']/@value" \
--value "test" xfce4-keyboard-shortcuts.xml
或者更简单:
xmlstarlet edit \
--update "//property[@name='XF86Display']/@value" \
--value "test" xfce4-keyboard-shortcuts.xml
这篇关于xmlstarlet 更新一个属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文