我正在编写一个处理xml文件的脚本。我想用xmlstarlet更新这个xml文件中的属性值,但它不起作用。
以下是该xml文件的示例:
<?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“更新属性的命令。
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此输出与输入严格相同……
谢谢
发布于 2011-10-20 23:22:48
这对我是有效的(根是<channel>;引用了属性值):
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发布于 2013-04-12 16:08:45
正确的方式(将动态更新设置)
xfconf-query -c xfce4-keyboard-shortcuts -p /commands/default/XF86Display -s 'test'https://stackoverflow.com/questions/7837879
复制相似问题