I\'m trying to insert 800 unique
elements into an existing set of 800 XML files. I generated 800 documents
The batch environment isn't terribly strongly suited for manipulating XML as XML. There's probably a way using Windows Script Host (VBScript or JScript) to evaluate the XML DOM, but in this situation it's probably easier just to use for
loops and echo
s.
Read the remarks in the following example script for a full explanation of how it works.
@echo off
setlocal
set "remarkDir=remarks\"
set "xmlDir=xml\"
rem // for all files in xmlDir\*.xml
for %%I in ("%xmlDir%\*.xml") do (
rem // echo filename without line break...
set /P "=Processing %%~nxI... ">"%%~dpnI.new" echo/%%X
rem // check whether the line contains /CHANGETIME
set "line=%%X"
setlocal enabledelayedexpansion
if not "%%X"=="!line:/CHANGETIME=!" (
rem // Line contains /CHANGETIME. Append remark.
>>"%%~dpnI.new" echo/!remark!
)
endlocal
)
rem // End of xml file. Replace old with new.
move /y "%%~dpnI.new" "%%~fI" >NUL
echo Done.
)
note: StackOverflow isn't intended to be a free coding service, but I have sympathy for you. It sounds like you've put a lot of effort into painting yourself into this corner. Therefore, I hope this helps you out.