on 11-26-2015 4:12 PM
Hi SDNites,
I have a string in which there are many special characters like &, <, > etc. and I wanted to remove the same. Is there any standard JAVA function (I have already done JAVA mapping for this scenario). which will address all the special characters and convert it to XML compatible characters so that I do not need to write the code for each special character.
Ex. & to be converted to &
Regards,
Abhi
Hello Abnishek,
As far as I know, there is no standard mapping function that would implement logic described by you (which is, XML symbols escaping). On the other hand, you may develop a small user defined function or function in function library that will implement XML escaping for a passed String variable.
There are various 3rd party libraries which can be used in order to easily perform characters escaping if you don't want to implement character escape logic by yourself (luckily, there are only 5 predefined symbols in XML which should be escaped). In one of recent projects, we used Apache Commons Lang (https://commons.apache.org/proper/commons-lang/) - precisely, its class StringEscapeUtils. Using it, you can escape XML string in just few code lines.
Regards,
Vadim
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.