How can I extract an STRING like "US_NY" between the tags <LOCATION></LOCATION>
from a XML file? I tried it with FINDSTR, but the line breaks are problematic.
<?xml version="1.0" encoding="utf-16"?>
<DEVICE>
<AGENT>
<VERSION>
2.0.0.2
</VERSION>
<CONNECTION>
<LOCATION>
US_NY
</LOCATION>
<SERVERIP>
127.0.0.1
</SERVERIP>
<TCPPORT>
5656
</TCPPORT>
<POLLINTERVAL>
5
</POLLINTERVAL>
</CONNECTION>
</AGENT>
</DEVICE>
To parse XML documents, use the XML PARSE statement, specifying the XML document that is to be parsed and the processing procedure for handling XML events that occur during parsing, as shown in the following code fragment.
When used in a command line, script, or batch file, %1 is used to represent a variable or matched string. For example, in a Microsoft batch file, %1 can print what is entered after the batch file name.
DOM Parser is the easiest java xml parser to learn. DOM parser loads the XML file into memory and we can traverse it node by node to parse the XML. DOM Parser is good for small files but when file size increases it performs slow and consumes more memory.
All major browsers have a built-in XML parser to access and manipulate XML.
Pure batch -
@ECHO OFF
SETLOCAL
SET "location="&SET "grab="
FOR /f "tokens=*" %%a IN (q19722041.xml) DO (
IF DEFINED grab SET location=%%a&SET "grab="
IF /i "%%a"=="<LOCATION>" SET grab=Y
)
ECHO found location=%location%
GOTO :EOF
where q19722041.xml is your source .xml
file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With