Here is the batch code to get version information from first title tag starting with 3DS from XML file:
@echo off
cls
echo.
echo.
echo ----------- Nintendo 3DS Firmware Checker --------------------------------------
echo --------------------- A CMD based Tool -----------------------------------------
echo.
echo.
echo.
del "%TEMP%
intendo3dsupdate.xml">nul 2>nul
set FirmwareVersion3DS=
httpget http://yls8.mtheall.com/ninupdates/feed.php "%TEMP%
intendo3dsupdate.xml"
for /F "usebackq tokens=3 delims=< " %%V in (`%SystemRoot%System32findstr.exe "<title>3DS" "%TEMP%
intendo3dsupdate.xml" 2^>nul`) do (
set "FirmwareVersion3DS=%%V"
goto OutputInfo
)
echo Failed to determine version of 3DS firmware!
echo.
goto :EndBatch
:OutputInfo
echo.
echo.
echo "%FirmwareVersion3DS%" is the current 3DS firmware.
echo.
echo.
set FirmwareVersion3DS=
:EndBatch
del "%TEMP%
intendo3dsupdate.xml">nul 2>nul
pause
The XML file is parsed first by command findstr searching for simple text string <title>3DS
returning
<title>3DS 9.4.0-21</title>
<title>3DS 9.3.0-21 (stage5)</title>
<title>3DS 9.3.0-21 (stage4)</title>
<title>3DS 9.3.0-21 (stage3)</title>
Those 4 lines each indented with 2 tabs are redirected directly to command for which splits each line using left angle bracket and space character as delimiter. Therefore first line is split to:
- token 1:
????????????????
(two horizontal tabs)
- token 2:
title>3DS
- token 3:
9.4.0-21
- token 4:
/title>
As just the version number is of interest, just token 3 is assigned to loop variable V assigned next to environment variable FirmwareVersion3DS.
For this task just the first line with a version information is of interest. So loop is exited with a jump to output the found version information after processing the first line returned by command findstr.
An error message is output instead of the version information if an error occurred like no XML file because of no connection to web server, or syntax in XML file changed in the meantime.
There is no check made if token 3 is really referencing the version information. Therefore the batch file code must be updated if for example spaces instead of tabs are output by the PHP script on server for indenting the lines.
The batch code deletes the XML file before downloading it from server to avoid parsing an old XML file. The XML file and the used environment variable are also deleted before exiting the batch file just for leaving a clean environment back.
EDIT:
The line with command for could be also
for /F "usebackq tokens=2 delims=< " %%V in (`%SystemRoot%System32findstr.exe "<title>3DS" "nintendo3dsupdate.xml" 2^>nul`) do (
There are 3 characters after delims=
:
- an angle bracket
<
and
- a horizontal tab character (not a sequence of spaces as browser displays) and
- a single space character.
The order of the delimiter characters is important as otherwise command line interpreter would exit batch script because of a syntax error.
The indenting tabs are ignored with this modification. Therefore now first line is split to:
- token 1:
title>3DS
- token 2:
9.4.0-21
- token 3:
/title>
And token 2 instead of 3 contains now the string of interest to output.
This solution is better than first one as it does not matter anymore if the line with the version string is indented with spaces or tabs or not indented at all.