Bat batch replacement of xml string will replace comments

The bat batch xml replacement will remove the ! comment

I wrote a bat script to replace the specified string in the xml file. After the replacement, all the strings in the xml

<!-注释-->

The ! in the comment will be replaced with empty, and there are not many resources on the Internet. After searching around, I couldn’t find a solution. Later, it was found that it was caused by the delayed variable, and the variable in the bat was real. . . Available codes are as follows:

   set dgPomPath=d:\xxx\xxx.xml
   set oldVersions=1.0.1
   set newVersions=1.0.2
   for /f "delims=" %%i in (%dgPomPath%) do (
   set "dgContent=%%i"
   setlocal enabledelayedexpansion
   set "dgContent=!dgContent:<revision>%oldVersions%</revision>=<revision>%newVersions%</revision>!"
   set "dgContent=!dgContent:<version>%oldVersions%</version>=<version>%newVersions%</version>!"
   echo !dgContent!>>$
   endlocal)
   move $ %dgPomPath%


Be careful not to enable setlocal enabledelayedexpansion externally, otherwise it will be replaced!

Guess you like

Origin blog.csdn.net/mashangzhifu/article/details/123520740