سؤال

I want to modify a value of a xml file using xmlstarlet (I know how to modify the line using grep or sed but I want to learn xmlstarlet).

I was looking the official documentation (http://xmlstar.sourceforge.net/doc/UG/xmlstarlet-ug.html) but I'm a total dissaster with the xml structure.

I want to modify the value here:

<ExtraDataItem name="GUI/UpdateDate" value=""/>

This is the command that I've tried, but the output is the same as input value:

xml edit --update "//ExtraDataItem[@name='GUI/UpdateDate']/@value" --value "never" virtualbox.xml

And this is the XML file:

<?xml version="1.0"?>
<!--
** DO NOT EDIT THIS FILE.
** If you make changes to this file while any VirtualBox related application
** is running, your changes will be overwritten later, without taking effect.
** Use VBoxManage or the VirtualBox Manager GUI to make changes.
-->
<VirtualBox xmlns="http://www.innotek.de/VirtualBox-settings" version="1.12-windows">
  <Global>
    <ExtraData>
      <ExtraDataItem name="GUI/DetailsPageBoxes" value="general,system,preview,display,storage,audio,network,usb,sharedFolders,description"/>
      <ExtraDataItem name="GUI/GroupDefinitions/" value="m=3fa2f128-b094-40c1-bec6-6580b0ac597a,m=65c3158a-330e-4456-b770-768dfecc788f"/>
      <ExtraDataItem name="GUI/HostScreenSaverDisabled" value="false"/>
      <ExtraDataItem name="GUI/Input/AutoCapture" value="true"/>
      <ExtraDataItem name="GUI/Input/HostKeyCombination" value="163"/>
      <ExtraDataItem name="GUI/LastItemSelected" value="m=Windows XP SP3 (x86)"/>
      <ExtraDataItem name="GUI/LastWindowPosition" value="575,245,770,550"/>
      <ExtraDataItem name="GUI/SplitterSizes" value="289,477"/>
      <ExtraDataItem name="GUI/SuppressMessages" value=",remindAboutInaccessibleMedia,cannotAccessUSB"/>
      <ExtraDataItem name="GUI/TrayIcon/Enabled" value="false"/>
      <ExtraDataItem name="GUI/UpdateCheckCount" value="3"/>
      <ExtraDataItem name="GUI/UpdateDate" value=""/>
    </ExtraData>
    <MachineRegistry>
      <MachineEntry uuid="{65c3158a-330e-4456-b770-768dfecc788f}" src="C:\Users\Administrador\VirtualBox VMs\Windows 7 x64\Windows 7 x64.vbox"/>
      <MachineEntry uuid="{3fa2f128-b094-40c1-bec6-6580b0ac597a}" src="C:\Users\Administrador\VirtualBox VMs\Windows XP SP3 (x86)\Windows XP SP3 (x86).vbox"/>
    </MachineRegistry>
    <MediaRegistry>
      <HardDisks/>
      <DVDImages/>
      <FloppyImages/>
    </MediaRegistry>
    <NetserviceRegistry>
      <DHCPServers>
        <DHCPServer networkName="HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter" IPAddress="192.168.56.100" networkMask="255.255.255.0" lowerIP="192.168.56.101" upperIP="192.168.56.254" enabled="1"/>
      </DHCPServers>
    </NetserviceRegistry>
    <SystemProperties defaultMachineFolder="C:\Users\Administrador\VirtualBox VMs" defaultHardDiskFormat="VDI" VRDEAuthLibrary="VBoxAuth" webServiceAuthLibrary="VBoxAuth" LogHistoryCount="3"/>
    <USBDeviceFilters/>
  </Global>
</VirtualBox>
هل كانت مفيدة؟

المحلول

The solution was to select the namespace:

xml ed -N N="http://www.innotek.de/VirtualBox-settings" --update "//N:ExtraDataItem[@name='GUI/UpdateDate']/@value" --value "never" virtualbox.xml
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top