xmlbashxml-namespacesxmlstarletopenbox

Update tag value according to attribute name xmlstarlet


I have a file :

<?xml version="1.0"?>
<openbox_config xmlns="http://openbox.org/3.4/rc" xmlns:xi="http://www.w3.org/2001/XInclude">
  <theme>
    <name>YYYY</name>
    <titleLayout>XXXX</titleLayout>
    <font place="ActiveWindow">
      <name>ZZZZ</name>
      <size>8</size>
    </font>
  </theme>
</openbox_config>

I am able to change the value of <name> and <titleLayout> with this command:

xmlstarlet ed -L -N a="http://openbox.org/3.4/rc" -u /a:openbox_config/a:theme/a:name -v YYYY test.xml

xmlstarlet ed -L -N a="http://openbox.org/3.4/rc" -u /a:openbox_config/a:theme/a:titleLayout -v XXXX test.xml

But I'm not able to change the value of <name> & <size> under <font place="ActiveWindow">. I have tried this, but it did not work:

xmlstarlet ed -L -N a="http://openbox.org/3.4/rc" -u /a:openbox_config/a:theme/a:font[@place="ActiveWindow"]/a:name -v AAAA test.xml

Any help?


Solution

  • Quote your path to prevent bash from interpreting the content:

    xmlstarlet ed -L -N a="http://openbox.org/3.4/rc" -u '/a:openbox_config/a:theme/a:font[@place="ActiveWindow"]/a:name' -v AAAA test.xml