使用 Windows 批处理解析 XML 文件 [英] Parse XML file with windows batch
本文介绍了使用 Windows 批处理解析 XML 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从 XML 文件中提取 <LOCATION></LOCATION>
标签之间的US_NY"之类的 STRING?我用 FINDSTR 试过了,但换行有问题.
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>
推荐答案
另外一个
@echo off
setlocal enableextensions enabledelayedexpansion
set "xmlFile=%~1"
for /f "tokens=1,2 delims=:" %%n in ('findstr /n /i /c:"<LOCATION>" "%xmlFile%"') do (
for /f "tokens=*" %%l in ('type "%xmlFile%" ^| more +%%n') do set "location=%%l" & goto endLoop
)
:endLoop
echo %location%
这篇关于使用 Windows 批处理解析 XML 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文