Bat 修改 xml 文件标签值


xml 文件如下:

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

 

修改 InstallationType 标签的值

@echo off
chcp 65001
setlocal EnableDelayedExpansion

set anotherVariable=kb-a-%date:~8,2%%date:~11,2%

(for /F "delims=" %%a in (file.xml) do (
   set "line=%%a"
   set "newLine=!line:InstallationType>=!"
   if "!newLine!" neq "!line!" (
      set "newLine=<InstallationType>%anotherVariable%</InstallationType>"
   )
   echo !newLine!
)) > newFile.xml

 

以上代码会修改 InstallationType 标签的值为 kb-a-0319,另存到文件 newFile.xml

 

参考链接:

https://stackoverflow.com/questions/17054275/changing-tag-data-in-an-xml-file-using-windows-batch-file

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM