最近使用apache common的XMLConfiguration来解析XML文件,最后发现这个工具在截取XML时遇到英文逗号,会自动截断。致使XML中属性值等不能用这个符号。apache
开始的时候,我用其余符号来代替英文逗号,而后获取到值后替换就好了。但是后来以为这个真是让人烦,就上网查了下,不少说法是禁用使用这个分隔符,方法以下:ide
XMLConfiguration config = new XMLConfiguration();
config.setDelimiterParsingDisabled(true);
工具
结果发现根本没有这个方法,后来查了源码,因为版本不一样个人这个新版本中是用如下的方法:AbstractConfiguration.setDelimiterParsingDisabled(true)的方式来消除。可是我以为这样的方法彷佛也不是很好。最后查看了XMLConfiguration类的源码,其中类上有这样一部分注释:this
By inheriting from AbstractConfiguration this class provides some extended functionality, e.g. interpolation of property values. Like in PropertiesConfiguration property values can contain delimiter characters (the comma ',' per default) and are then split into multiple values. This works for XML attributes and text content of elements as well. The delimiter can be escaped by a backslash. As an example consider the following XML fragment:
<config>
<array>10,20,30,40</array>
<scalar>3\,1415</scalar>
<cite text="To be or not to be\, this is the question!"/>
</config>spa
NND,原理只须要在逗号前家个“\”这样的符号来转义就好了,这样就不用那样设置了。但是以前从网上也没有人这样说,看来有的时候看源码仍是比较好,已经屡试不爽了。这里记录下,但愿能帮一些同志解决下燃眉之急。scala