1

我想使用 xmlstarlet 修改 xml 文件的值(我知道如何使用 grep 或 sed 修改行,但我想学习 xmlstarlet)。

我正在查看官方文档(http://xmlstar.sourceforge.net/doc/UG/xmlstarlet-ug.html),但我对 xml 结构完全是个灾难。

我想在这里修改值:

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

这是我尝试过的命令,但输出与输入值相同:

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

这是 XML 文件:

<?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>
4

1 回答 1

1

解决方案是选择命名空间:

xml ed -N N="http://www.innotek.de/VirtualBox-settings" --update "//N:ExtraDataItem[@name='GUI/UpdateDate']/@value" --value "never" virtualbox.xml
于 2013-04-13T19:29:23.153 回答