Read an XML entry from a batch file and save the values ​​in a variable (fixed Json output to xml)


I have been researching on how to read a xml input file into a batch file to read compare the data, but not had much luck.

This data will need then to be stored as a variable so we can compare the values.

There are a total of 4 values we need to measure, these are, temperature, ph, nh3 and o2

Because these values can change every hour when the data is pulled we need a way of comparing the data with a set value such as:


Is this possible?

Many thanks to all who responds.

I have included the xml file below:

This works with the data you have now posted.

@echo off
for %%a in (temperature ph nh3 o2) do (
   for /f "tokens=2 delims=</>" %%b in ('type "[Megafileupload]Seneye_Reading.xml" ^|findrepl "(<.*?>.*?</.*?>)" "$1\r\n" ^|findrepl "><" ">\r\n<" ^|findrepl ".*<%%a>.*" /e:".*</%%a>.*" /b:".*<curr>" ') do set "123-%%a=%%b"
set 123

This uses a helper batch file called findrepl.bat (by aacini) - download from:

Place findrepl.bat in the same folder as the batch file or on the path.