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

advertisements

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:

IF ph=7.8 GOTO PHHIGH ELSE OK

Is this possible?

Many thanks to all who responds.

I have included the xml file below:

http://s1.uploads.im/KriCJ.jpg


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
pause

This uses a helper batch file called findrepl.bat (by aacini) - download from: https://www.dropbox.com/s/rfdldmcb6vwi9xc/findrepl.bat

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