xmlstarlet update an attribute

后端 未结 2 1156
傲寒
傲寒 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 07:06

    This works for me (the root is ; 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
    

提交回复
热议问题