xmlstarlet编辑插入语法

时间:2011-10-07 23:14:48

标签: xml xmlstarlet

我正在尝试使用xmlstarlet插入一个新元素,但是当我运行该命令时,它只列出我要插入的xml文件。任何建议都会很棒。

xml ed -s /chkSys/machine/registry -t elem -n key -v "" -i /registry/key -t attr -n value -v "'C:\Program Files\Microsoft SQL Server'" -v path "HKLM\software\symantec\Symantec Endpoint Protection\AV\Exclusions\ScanningEngines" --net \\server3\e$\temp\chksys\chksys.xml

##Old##
<?xml version="1.0" encoding="utf-8"?>
<chksys>
    <machine>
        <registry>

       </registry>
    </machine>
</chksys>

##New##
<?xml version="1.0" encoding="utf-8"?>
 <chksys>
    <machine>
       <registry>
           <key value="'C:\Program Files\Microsoft SQL Server'" path "HKLM\software\symantec\Symantec Endpoint Protection\AV\Exclusions\ScanningEngines\Directory\Admin\1075182566\DirectoryName"/>
       </registry>
    </machine>
 </chksys>

1 个答案:

答案 0 :(得分:2)

你的命令有点偏,你应该在插入时使用键的完整路径:

xml ed --net ^
    -s /chksys/machine/registry -t elem -n key -v "" ^
    -i /chksys/machine/registry/key -t attr -n value ^
      -v "'C:\Program Files\Microsoft SQL Server'" ^
    -i /chksys/machine/registry/key -t attr -n path ^
      -v "HKLM\software\symantec\Symantec Endpoint Protection\AV\Exclusions\ScanningEngines" ^
    OLDFILE > NEWFILE

这会将编辑过的xml放在NEWFILE中,如果要直接更改OLDFILE,可以使用--inplace或-L选项。

xml ed --net --inplace ^
    ...
相关问题