@echo off
rem findthis.bat
rem Parameter 1 is (XML element one) to find eg. section
rem Parameter 2 is (XML element two) to find eg. chapter
rem Parameter 3 is string to find
rem Parameter 4 is (XML) file(spec)
set fstr=
set fsection=
set fchapter=
set fis=%1
set xdot=
@for /F "delims=. tokens=1*" %%x in ("%1") do @set xdot=%%y 
if JUNK%xdot%==JUNK goto domore1
type %1 > n%1.jnk
if errorlevel 1 goto aster
if not exist n%1.jnk goto aster
rem no prefixes
goto bigokay
:domore1
set xdot=
@for /F "delims=. tokens=1*" %%x in ("%2") do @set xdot=%%y
if JUNK%xdot%==JUNK goto domore2
set fstr=%1
shift
type %1 > n%1.jnk
if errorlevel 1 goto aster
if not exist n%1.jnk goto aster
rem no prefixes
goto bigokay
:domore2
set xdot=
@for /F "delims=. tokens=1*" %%x in ("%3") do @set xdot=%%y
if JUNK%xdot%==JUNK goto domore3
set fsection=%1
set fstr=%2
shift
shift
find "%fsection% " %1 > n%1.jnk
if errorlevel 1 goto aster+
if not exist n%1.jnk goto aster
find /V "%fsection% " %1 > x%1.jnk
goto bigokay
:domore3
set fsection=%1
set fchapter=%2
set fstr=%3
shift
shift
shift
:top
rem echo %1 %fsection% %fchapter% %fstr%
if JUNK%1==JUNK goto nomore
set xz=
@for /f "delims=* tokens=1*" %%x in ("x%1") do @set xz=%%y 
if JUNK%xz%==JUNK goto okay
goto aster  
:okay
if not exist %1 goto nomore
@find "%fsection% " %1 > n%1.jnk
rem if errorlevel 1 goto aster
if not exist n%1.jnk goto aster
if JUNK%fchapter%==JUNK goto bigokay
@find /V "%fsection% " %1 > x%1.jnk
@find "%fchapter% " x%1.jnk >> n%1.jnk
:bigokay
echo. > ~%1~
@for /f "delims=\n tokens=1*" %%x in (n%1.jnk) do (@for %%i  in (%%x %%y) do echo %%i %%j) >> ~%1~
if JUNK%fstr%==JUNK goto nomore
find /c "%fstr%" ~%1~
if exist n%1.jnk erase n%1.jnk
if exist x%1.jnk erase x%1.jnk
erase ~%1~
shift
goto top
:aster
@for %%x in (%1) do @findthis.bat %fsection% %fchapter% %fstr% %%x
:nomore
