How can I read the values from XML using batch file?
<?xml version="1.0" encoding="UTF-16"?>
<PARENT>
<FTP>
<SAMPLE>
<FILE>test.xls</FILE>
<OUTBOX>testoutbox</OUTBOX>
<ARCHIVE>location</ARCHIVE>
</SAMPLE>
</FTP>
</PARENT>
How can I read the values from XML using batch file?
<?xml version="1.0" encoding="UTF-16"?>
<PARENT>
<FTP>
<SAMPLE>
<FILE>test.xls</FILE>
<OUTBOX>testoutbox</OUTBOX>
<ARCHIVE>location</ARCHIVE>
</SAMPLE>
</FTP>
</PARENT>
@ECHO OFF
SETLOCAL
:: remove variables starting $
FOR /F "delims==" %%a In ('set $ 2^>Nul') DO SET "%%a="
FOR /f "tokens=2-4delims=<>" %%a IN (q26985813.txt) DO (
IF /i "/%%a"=="%%c" SET "$%%a=%%b"
)
SET $
GOTO :EOF
I used a file named q26985813.txt containing your data for my testing.
Note that the first for removes all variables beginning $ from the environment.
Data is returned in variables $file, $outbox etc - simply prefixed by the $ in the obvious place. In this way, the routine will set up the variables it finds in the file; if your tagnames change, so will the variables delivered.
The routine relies on the relavant data lines being indented.