XMLConfiguration中不能使用英文逗号的解决办法

最近使用apache common的XMLConfiguration来解析XML文件,最后发现这个工具在截取XML时遇到英文逗号,会自动截断。导致XML中属性值等不能用这个符号。

开始的时候,我用其他符号来代替英文逗号,然后获取到值后替换就行了。可是后来觉得这个真是让人烦,就上网查了下,很多说法是禁用使用这个分隔符,方法如下:

        XMLConfiguration config = new XMLConfiguration();  
        config.setDelimiterParsingDisabled(true); 

        结果发现根本没有这个方法,后来查了源码,由于版本不同我的这个新版本中是用以下的方法:AbstractConfiguration.setDelimiterParsingDisabled(true)的方式来消除。但是我觉得这样的方法似乎也不是很好。最后查看了XMLConfiguration类的源码,其中类上有这样一部分注释:

    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>

     NND,原理只需要在逗号前家个“\”这样的符号来转义就行了,这样就不用那样设置了。可是之前从网上也没有人这样说,看来有的时候看源码还是比较好,已经屡试不爽了。这里记录下,希望能帮一些同志解决下燃眉之急。


  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值