Batch Insert Element from XML with Shared Filename

后端 未结 3 1515
春和景丽
春和景丽 2020-12-12 06:31

I\'m trying to insert 800 unique this is a remark elements into an existing set of 800 XML files. I generated 800 documents

3条回答
  •  有刺的猬
    2020-12-12 06:46

    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 echos.

    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.

提交回复
热议问题