0

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>
2
  • Thanks, I actually saw that post but can't work it out a while ago. What I did was, I copied his XML and used that instead of mine and It works.. so the problem was is my XML. Commented Nov 18, 2014 at 3:40
  • You will need to add carriage returns to each value to make it work with the referenced solution. You can try to modify the script to avoid the carriage return check. Commented Nov 18, 2014 at 3:56

1 Answer 1

0
@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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.