2011-10-20 15 views
2

私はXMLファイルを処理するスクリプトを作成しています。 このxmlファイルの属性値をxmlstarletで更新したいのですが、動作しません。ここでxmlstarletは属性を更新します

は、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="&lt;Alt&gt;F2" type="empty"/> 
     <property name="&lt;Control&gt;&lt;Alt&gt;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="&lt;Alt&gt;F2" type="string" value="xfrun4"/> 
     <property name="&lt;Control&gt;&lt;Alt&gt;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 

この出力は厳密には入力に同じです...

は、(ルートが<channel>であり、属性値が引用された)これは私のために働くあなたに

答えて

3

ありがとう:

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 
+0

おかげで、私は引用符と二重引用符を逃しました。.. – renard

0

適切な方法(その場で設定を更新します)、それは魔法のように動作

xfconf-query -c xfce4-keyboard-shortcuts -p /commands/default/XF86Display -s 'test' 
関連する問題