xmlstarlet update an attribute

后端 未结 2 1157
傲寒
傲寒 2021-01-20 06:31

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.

Here is a sample

相关标签:
2条回答
  • 2021-01-20 06:45

    The proper way (will update settings on the fly)

    xfconf-query -c xfce4-keyboard-shortcuts -p /commands/default/XF86Display -s 'test'
    
    0 讨论(0)
  • 2021-01-20 07:06

    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
    

    Or simpler:

    xmlstarlet edit \
      --update "//property[@name='XF86Display']/@value" \
      --value "test" xfce4-keyboard-shortcuts.xml
    
    0 讨论(0)
提交回复
热议问题