Windows批处理文件 - 在一个XML文件替换字符串 [英] Windows batch file - replace a string in an XML file
本文介绍了Windows批处理文件 - 在一个XML文件替换字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有下面的XML文件:
I have the following XML file:
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
<appSettings>
<add key="Name1" value="Value1"/>
<add key="Name2" value="Value2"/>
<add key="Name3" value="Value3"/>
</appSettings>
<runtime>
<legacyUnhandledExceptionPolicy enabled="true"/>
</runtime>
</configuration>
我需要更换值2到服务器名称使用Windows批处理文件编程。
I need to replace "Value2" to "ServerName" using Windows Batch file programming.
可能有人帮一把,因为我是新来的Windows批处理编程?
Could anybody help one as I am new to Windows Batch programming?
推荐答案
批将有以&lt;,>麻烦,^和&安培;字符。
这将工作,但一个JScript / VBScript的脚本(一个评论引用等)是一个更好的解决方案。
Batch will have trouble with <, >, ^ and & characters. This will work, but a JScript/VBScript script (like is referenced in one of the comments) is a much better solution.
更改原始的文字被搜索,而替换的新文本。我推荐的Windows脚本来学习的JScript。
Change "ORIGINAL" to the text being searched for, and "REPLACE" to the new text. I recommend for Windows scripting to learn JScript.
@echo off
for /f "tokens=* delims=" %%f in ('type sometext.txt') do CALL :DOREPLACE "%%f"
GOTO :EOF
:DOREPLACE
SET INPUT=%*
SET OUTPUT=%INPUT:ORIGINAL=REPLACE%
for /f "tokens=* delims=" %%g in ('ECHO %OUTPUT%') do ECHO %%~g>>out.txt
EXIT /b
:EOF
这篇关于Windows批处理文件 - 在一个XML文件替换字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文