xml类型的配置文件包含特殊字符的处理
resin的配置文件类似xml,语法规范也遵循xml的写法,今天遇到了特殊字符的问题,数据库密码包含了特殊字符。
<init-param driver-name=”oracle.jdbc.driver.OracleDriver”/>
<init-param url=”jdbc:oracle:thin:@localhost:1521:Test”/>
<init-param user=”username”/>
<init-param password=”123&(45aq”/>
…
</resource-ref>
#sh start_server.sh
Starting Resin on Thu, 22 Apr 2010 18:39:48 +0800 (CST)
com.caucho.xml.XmlParseException: /home/resin/conf/resin.conf:8: malformed entity ref at `(‘
at com.caucho.xml.XmlParser.error(XmlParser.java:2769)
at com.caucho.xml.XmlParser.parseCharacterReference(XmlParser.java:1002)
at com.caucho.xml.XmlParser.parseValue(XmlParser.java:1192)
at com.caucho.xml.XmlParser.parseAttributes(XmlParser.java:702)
at com.caucho.xml.XmlParser.parseElement(XmlParser.java:603)
at com.caucho.xml.XmlParser.parseNode(XmlParser.java:377)
at com.caucho.xml.XmlParser.parseInt(XmlParser.java:248)
at com.caucho.xml.AbstractParser.parse(AbstractParser.java:645)
at com.caucho.util.Registry.parse(Registry.java:199)
at com.caucho.util.Registry.parse(Registry.java:174)
at com.caucho.server.http.ResinServer.init(ResinServer.java:311)
at com.caucho.server.http.ResinServer.main(ResinServer.java:1176)
其原因并不是“(”引起的,罪魁祸首是“&”
解决办法是使用&替换&
如:
<init-param password=”123&(45aq”/>
xml文件中其他的几个特殊字符做同样处理即可:
* & = & (ampersand)
* < = < (left angle bracket, less-than sign)
* > = > (right angle bracket, greater-than sign)
* " = ” (quotation mark)
* ' = ‘ (apostrophe)
本文固定链接: https://www.2hei.net/2010/04/22/xml_specifications/ | 2hei.net