XMLConfiguration中不能使用英文逗號的解決辦法

最近使用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

相關文章
相關標籤/搜索