转义xml中的特殊字符

时间:2016-10-13 09:23:55

标签: java xml escaping special-characters

我在以下xml文件中运行此查询:

errorEvt.code===Something.CLOSE_NORMAL

我收到以下错误:

  

ERROR]:发生异常,终止。   java.lang.IllegalArgumentException:异常解析或评估   ClassService.getParameter(\"参数1 \&#34)

如何逃避"正确?

1 个答案:

答案 0 :(得分:0)

为此只使用CDATA部分怎么样?

 <![CDATA[
 Within this Character Data block I can
 use double dashes as much as I want (along with <, &, ', and ")
 *and* %MyParamEntity; will be expanded to the text
 "Has been expanded" ... however, I can't use
 the CEND sequence (if I need to use it I must escape one of the
 brackets or the greater-than sign).
 ]]>

或者这不符合您的要求吗?

所以它看起来与此相似:

<?xml version="1.0" encoding="UTF-8"?>
..
...
<query> 
     <![CDATA[
     update tableX set colName='$ClassService.getParameter(\"param1\")$' where id = '0'
     ]]>
</query>
...