Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
672 views
in Technique[技术] by (71.8m points)

Parse XML file with windows batch

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should use XML.EXE within batch to read an XML file. For more details go to http://xmlstar.sourceforge.net/

Batch File:

@echo off
for /f %%i in ('XML.EXE sel -t -v "//LOCATION" CP.xml') do set var=%%i
echo LOCATION is %var%

output:

LOCATION is US_NY

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...