使用Windows批处理文件的XML文件更改标签数据 [英] Changing tag data in an XML file using windows batch file

查看:988
本文介绍了使用Windows批处理文件的XML文件更改标签数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有它几个标签一个XML文件,我试图改变这些标签中的一个内容与批处理脚本。

I have an XML file with several tags in it, and I am trying to change the contents of one of these tags with a batch script.

XML文件的一个例子是:

An example of the xml file is:

<ConfigurationData>
<ReportsFolder>\Reports</ReportsFolder>
<Helpfolder>\Help</HelpFolder>
<InstallationType>Terminal</InstallationType>
<LicenseFolder>..\License</LicenseFolder>
</ConfigurationData>

我试图改变之间的&LT数据; InstallationType&GT; &LT; / InstallationType&GT; 另一个变量我的选择。我想我需要某种形式的for循环来查找XML文件的一部分,但我失去了作为我将如何修改只是一个部分。

I am trying to change the data between <InstallationType> and </InstallationType> to another variable of my choosing. I'm thinking I would need some sort of For loop to find that part of the xml file, but I'm lost as to how I would edit just that one section.

推荐答案

您真的应该使用专门设计来操作XML的工具。

You really should use a tool that is designed specifically to manipulate XML.

但在紧要关头,你可以使用任何工具,可以做一个正则表达式搜索和替换做一个天真的解决方案,将与你有它奠定了该文件的工作,但可能会失败,并具有逻辑上等价的XML文件曾经的物理布局重新排列。

But in a pinch, you could use any tool that can do a regex search and replace to do a naive solution that would work with the file as you have it laid out, but might fail with a logically equivalent XML file that has had the physical layout rearranged.

我喜欢用一种混合的JScript /批工具我编写的名为 REPL.BAT 通过批处理脚本来处理文本文件。该脚本会从XP的任何原生的Windows机器上运行以后,它不需要安装任何第三方可执行文件。点击链接以获取脚本code和更全面的描述。

I like to use a hybrid JScript/batch utility I wrote called REPL.BAT to manipulate text files via batch scripts. The script will run on any native Windows machine from XP onward, and it does not require installation of any 3rd party executables. Click the link to get the script code and a more thorough description.

使用REPL.BAT,快速,高效的,但天真的解决办法很简单,只要:

Using REPL.BAT, a fast and efficient but naive solution is as simple as:

setlocal enableDelayedExpansion
set "newValue=myNewValue"
type "fileName.xml"|repl "(<InstallationType>).*(</InstallationType>)" "$1!newValue!$2" >fileName.xml.new
move /y "fileName.xml.new" "fileName.xml"

这篇关于使用Windows批处理文件的XML文件更改标签数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆