我正在解析如下的 XML文件: ?xml version="1.0"?!----configuration settings connections connection name="name1" value="connection1" type="abc"/ connection name="name2" value="connection2" type="def"/ /connections /settings/configur
<?xml version="1.0"?> <!-- --> <configuration> <settings> <connections> <connection name="name1" value="connection1" type="abc"/> <connection name="name2" value="connection2" type="def"/> </connections> </settings> </configuration>
从批处理文件中,我提示用户输入连接名称.我想解析XML获取具有指定名称的连接并获取其值.所以如果用户给出name1,我想选择connection1.我从Extract XML Tag Values (Based on a Flag) Using Batch获得了以下代码
我不熟悉for循环(特别是分隔符,令牌)批处理文件,所以我不确定这是如何工作的,以及如何使它适合我.
(for /F "tokens=1,2 delims== " %%a in (connection.config) do ( if "%%~b" neq "" set %%a=%%~b if /I "!name!" equ "%name%" echo !value! ))如果您使用正确的令牌和分隔符,它可以工作:
@echo off&setlocal for /F tokens^=2^,3^,5delims^=^<^"^= %%a in (connection.config) do ( if "%%a" equ "connection name" echo(%%b %%c )
输出是:
name1 connection1 name2 connection2