开发者

valid xml element in java replaceAll doesnt seem working well

开发者 https://www.devze.com 2022-12-27 14:16 出处:网络
Im trying to create a xml file from a POJO , in which i have a property that stores urls, I have been using the below method to replace all & in the url String to make the xml conform to standards

Im trying to create a xml file from a POJO , in which i have a property that stores urls, I have been using the below method to replace all & in the url String to make the xml conform to standards and pass it as an html char entity 开发者_Python百科but the string does not change.

public static String forHrefAmpersand(String aURL){
    return aURL.replaceAll("&", "&");
}

the value might be www.abc.com/controller?a=1&next=showResults

I have even tried changing the above method to use "/" as i read replaceAll uses regular expression but replaceAll is not working as expected, Can anyone tell me what is the mistake im doing ? Thanks in advance


There is probably a bug somewhere else in your code. I suggest to print the string which forHrefAmpersand() returns to System.out. It should contain the value which you expect.

PS: If you're using Java 5, you can use String.replace() instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消