Quantcast
Channel: A batch file to extract the value of a specific XML tag - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by kikuchiyo for A batch file to extract the value of a specific XML tag

$
0
0

I don't have a windows machine, so forgive if the syntax is a little off, but something like this may help, if the data is as you listed in your example, though you may want to consider using Powershell, as it has excellent tools for dealing with XML:

setlocal enabledelayedexpansionset start_reading="0"set stop_reading="0"set your_file_name=%~1if EXIST "%your_file_name%.txt" del "%your_file_name%.txt"for /f "eol=; tokens=1 delims=" %%c in ('type "%your_file_name_here%.xml"') do (  set line=%%c  @REM Determine if at start of Data Tag  for /f "eol=; tokens=1 delims=" %%d in ('echo !line! ^| findstr /i /c:"<DATA>"') do (    set start_reading="1"  )  @REM Determine if at end of Data Tag  for /f "eol=; tokens=1 delims=" %%d in ('echo !line! ^| findstr /i /c:"</DATA>"') do (    set stop_reading="1"  )  @REM stop reading DATA tag input  if "!stop_reading!"=="1" (    set start_reading="0"  )  @REM skips first line assumed to be <DATA>  if "!start_reading!"=="2" (    echo !line! >> "%your_file_name_here%.txt"  )  @REM Ready to start reading post <DATA> line  if "!start_reading!"=="1" (    set stop_reading="0"    set start_reading="2"  ))@REM Check resultstype "%your_file_name_here%.txt"

Let me know if you need help. I have had to work in environments, where DOS was all they would let us use, so I feel your pain. Good luck! :)


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>