我正在使用xmlstarlet编辑xml文件。我特别关注这两个命令的问题。
xml ed -P --update /ns2:ExportManifest/ExportManifestEntity[@path='home/user_name/11.05 CFD Developer commits.xanalyzer']/ExportManifestProperty/EntityMetaData/@name -v 11.05 CFD Developer commits.xanalyzer someFile.xml > someFileNew.xml & move /Y someFileNew.xml someFile.xml
这个命令没有做到它应该做的事情。运行上面的命令后,我发现文件为空。有什么我需要逃避才能使这个命令工作吗?
第二个有百分号。我发现在批处理文件中我可以使用%%
来转义它。但它似乎没有正常工作,我找到一个与上面相同的空文件。
xml ed -P --update /ns2:ExportManifest/ExportManifestEntity[@path='home/user_name/11.05.DEV CFD commits %%28feature %%26 bug%%29 by Program.xanalyzer']/ExportManifestProperty/EntityMetaData/@name -v 11.05.DEV CFD commits (feature & bug) by Program.xanalyzer someFile.xml > someFileNew.xml & move /Y someFileNew.xml someFile.xml
有什么想法吗?
答案 0 :(得分:0)
在批处理文件中执行xmlstarlet命令时,必须非常小心属性值中的空格。我不得不使用""
告诉窗口,这里的所有内容都是String
。但我也必须使用''
来确保属性值被成功读取和匹配。这是解决方案:
将替换旧值的新值也应该是双引号。
xml ed -P --update /ns2:ExportManifest/ExportManifestEntity[@path="'home/user_name/11.05 CFD Developer commits.xanalyzer'"]/ExportManifestProperty/EntityMetaData/@name -v "11.05 CFD Developer commits.xanalyzer" someFile.xml > someFileNew.xml & move /Y someFileNew.xml someFile.xml
我为第二个命令做了同样的事情:
xml ed -P --update /ns2:ExportManifest/ExportManifestEntity[@path="'home/user_name/11.05.DEV CFD commits %%28feature %%26 bug%%29 by Program.xanalyzer'"]/ExportManifestProperty/EntityMetaData/@name -v "11.05.DEV CFD commits (feature & bug) by Program.xanalyzer" someFile.xml > someFileNew.xml & move /Y someFileNew.xml someFile.xml