@ECHO OFF
SETLOCAL
CALL :zapvars
FOR /f "tokens=2,3delims=<>" %%i IN (myxml.xml) DO (
CALL :analyse %%i
IF DEFINED tlist SET list=%%i
IF DEFINED tentry SET entry=%%j
IF DEFINED ttoken SET token=%%j
IF DEFINED toutput SET output=%%j
)
GOTO :eof
:analyse
FOR %%a IN (tlist tentry ttoken toutput) DO (SET %%a=)
ECHO %1|FINDSTR /b "list" >NUL
IF NOT ERRORLEVEL 1 SET tlist=Y&GOTO :EOF
IF "%1"=="entry" SET tentry=Y&GOTO :EOF
IF "%1"=="output" SET toutput=Y&GOTO :EOF
IF "%1"=="token" SET ttoken=Y&GOTO :EOF
IF NOT "%1"=="/%list%" GOTO :EOF
:: Found end of list
ECHO list=%list% entry=%entry% output=%output% token=%token%
:zapvars
FOR %%z IN (list entry output token) DO (SET %%z=)
GOTO :eof
Really not that hard. Question is what you want to do with it once it's in the envvars. Obviously, if you want to check for missing elements, all you need do is use the results only if defined list if defined entry if defined output if defined token
Given the input format, each line is tokenised using < and > The first selected token is applied to %%i and the second to %%j. The first token on the line is the leading spaces.
%%i therefore will be the node name. For each line, the node name is passed to the subroutine :analyse for er, analysis.
:analyse first clears each of the flags tname meaning token is aname. First cab off the rank is to see whether the token startslist, so the token isECHOed intoFINDSTRwhich looks for a line beginning (/b`) "list". If findstring finds what it's looking for, ERRORLEVEL is set to 0, else non-zero.
If errorlevel is not 1 or greater then TLIST is set to Y It could be set to anything - just long as it's set to SOMETHING. The subroutine then exits.
If it wasn't a token beginning list then :analyse loos for each of the target tokens. If it finds one, it sets the appropriate flag.
Finally, if the token isn't /LISTNAMEBEINGPROCESSED then the routine exits. If /list... IS found, then the value-tokens are displayed and then cleared.
Meanwhile, back in the FOR loop, following a call to :analyse, the routine's decision is contained in at most ONE of (tlist,tentry,ttoken,toutput) beging SET in the environment. If tname is set, then the corresponding value-token is assigned from the appropriate metavariable - %%i - the listname if tlist is set, and %%j - the data item for the others. For the nodes that are of no interest, no flags are returned by :analyse so the FOR loop simply proceeds to the next line.