Anton Shevtsov
Anton Shevtsov

Reputation: 1299

Xmlstarlet | remove entry with specified value

I have something like this

<?xml version="1.0"?>
<!DOCTYPE Menu PUBLIC "-//freedesktop//DTD Menu 1.0//EN" "http://www.freedesktop.org/standards/menu-spec/1.0/menu.dtd">
<Menu>
  <Menu>
    <Name>Personal</Name>
    <Directory>xfce-personal.directory</Directory>
    <Include>
      <And>
        <Category>Settings</Category>
        <Category>X-XFCE-SettingsDialog</Category>
        <Category>X-XFCE-PersonalSettings</Category>
      </And>
      <Filename>brightness-frontend.desktop</Filename>
      <Filename>xscreensaver-properties.desktop</Filename>
    </Include>
  </Menu>
</Menu>

I want remove

 <Filename>brightness-frontend.desktop</Filename>

Try run xmlstartlet

/usr/bin/xmlstarlet ed -d  "//Include[Filename='brightness-frontend.desktop']"  /tmp/1.xml

But remove all Include section, with all children. How remove only Filename node with brightness-frontend.desktop value?

Upvotes: 1

Views: 339

Answers (1)

Tris
Tris

Reputation: 293

The XPath query //Include[Filename='...'] will match the Include node itself, which includes all children underneath it. Note that Filename is a separate XML element, not a property on the Include attribute.

Instead, use an XPath query that matches the Filename attribute based on its text:

//Filename[text()='brightness-frontend.desktop']

Upvotes: 3

Related Questions