(for /F "delims=" %%a in (Settings.xml) do (
set "line1=%%a"
set "newLine1=!line1:DefaultLatitude>=!"
if "!newLine1!" neq "!line1!" (
set "newLine1=<DefaultLocation>%newLoc%</DefaultLocation>"
)
echo !newLine1!
)) > newFile.xml
copy newFile.xml Settings.xml
我正在使用它来修改Settings.xml中DefaultLocation的值,如何扩展它以便能够在同一个函数中修改多个标签?
目前我只是复制并粘贴它,似乎效率低下
答案 0 :(得分:0)
使用带有"from|to"
值的内循环(|
看起来不错,不太可能在您的值中使用):
(for /F "delims=" %%a in (Settings.xml) do (
set "line=%%a"
for %%b in (
"DefaultLatitude>|<DefaultLocation>%newLoc%</DefaultLocation>"
"herp>|<foo>%foo%</foo>"
"derp>|<bar>%bar%</bar>"
) do for /f "delims=| tokens=1,2" %%c in (%%b) do (
if "!line:%%c=!" neq "!line!" set "line=%%d"
)
echo.!line!
)) > newFile.xml
echo.
用于正确打印空行