从批处理脚本解析XML时出现意外字符 [英] unexpected character while parsing XML from batch script
问题描述
我在尝试从批处理脚本解析XML时收到此错误
I am getting this error when I am trying to parse XML from batch Script
error :
< was unexpected at this time.
xml:
<driver type=".dbdriver">
<attributes>localhost;1521;XE;false</attributes>
<driverType>Oracle thin</driverType>
</driver>
<password>7ECE6B7E7D2AF514C55BAE8B3A6B51E7</password>
<user>JR</user>
批处理scrpit:
for /f "tokens=3 delims=><" %%j in ('type %SETTINGSPATH% ^| find "<user>"') do set user=%%j
这段代码应该从XML读取用户值,这只是JR,在一些机器上我得到这个值;但有些机器不显示此值并显示此错误。
This code is supposed to read user value from XML which is just "JR" and on some machines I am getting this values; but some machines are not showing this value and showing this error.
请指导。
推荐答案
使用批处理解析XML通常是有问题的,并且总是有风险的。一个有效的XML文档可以被合法地重新格式化任何数量的方式,将打破你的解析器。但是如果你真的想继续使用批处理...
Parsing XML with batch is often problematic and always risky. A valid XML documented could be legitamately reformatted in any number of ways that would break you parser. But if you really want to continue to use batch...
当你有一个非转义和无引号的<
字符在IN()子句中。 < user>
已经被引用,因此通常不应该是问题。该问题必须来自%SETTINGSPATH%
中包含的值。值必须具有非引号和非转义的<
,或者值中必须有奇数个引号。奇数个引号会导致< user>
不再引用。
That error message occurs when you have an unescaped and unquoted <
character in your IN() clause. The "<user>"
is already quoted, so that normally should not be a problem. The problem must stem from the value contained in %SETTINGSPATH%
. Either the value must have an unquoted and unescaped <
, or there must be an odd number of quotes in the value. The odd number of quotes would cause the <user>
to no longer be quoted.
是你没有向我们显示所有的代码,错误发生在别的地方。
The only other possibility is that you have not shown us all your code, and the error is occuring someplace else.
这篇关于从批处理脚本解析XML时出现意外字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!