xmlstarlet编辑插入语法

问题描述:

我试图用xmlstarlet插入一个新元素,但是当我运行该命令时,它只是列出了我试图插入到的xml文件。任何建议都会很棒。xmlstarlet编辑插入语法

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> 

你的命令是有点过,当你插入你应该使用完整路径键:

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^
    ...