Batch – get tag value from XML file


I have this following XML file called “test.xml”

how can I get “Agent-name-8181818” value from “ragent-name” tag into a variable within a batch file?

    <configuration-info ts="26-02-2018_15-31-54">
        <ragent-name ts="26-02-2018_15-31-54">Agent-name-8181818</ragent-name>
        <site ts="26-02-2018_15-31-54">site</site>


With xpath.bat (does not require external binaries , just uses built-in windows capabilities):

call xpath test.xml "*//configuration-info/ragent-name"

to assign result to a variable:

for /f "tokens=* delims=" %%# in ('call xpath test.xml "*//configuration-info/ragent-name"') do set "reagent=%%#"

Answered By – npocmaka

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published