computing
  • 7

Solved Read Specific Content Of An XML File Through Batch File

  • 7

I am trying to read the content of XML file to get a particular value from a tag and export in another .txt or .xls file. The XML file looks like:

<definition name=”.test1″ extends=”.b”>
<put name=”id” value=”TR012″ />
</definition>

<definition name=”.test2″ extends=”.b”>
<put name=”id” value=”TR013″ />
</definition>

The XML file has multiple such entries and i want to read:
1) the value in name property of definition tag
2) the value in value property of <put> tag

Currently when i tried i got only the last value and not all of them. Is it possible to retrieve internal specific values and export to another file through BAT file?
Need Help on this piece

Share

1 Answer

  1. @echo off & setlocal
    for /f “tokens=1,2,3* delims==” %%a in (C:\\test.xml) do (
    if /i “%%a” equ “<definition name” call :zz %%b
    if /i “%%a” equ “<put name” call :zz “%%~c”
    )
    goto :eof

    :zz
    echo %~1
    ::=== not fully test, might need tweaked.

    • 0