cancel
Showing results for 
Search instead for 
Did you mean: 

String to XML

itabhishek9
Participant
0 Kudos

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 &amp;

Regards,

Abhi

Accepted Solutions (0)

Answers (2)

Answers (2)

vadimklimov
Active Contributor
0 Kudos

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

former_member186851
Active Contributor
0 Kudos

Hello Abhishek,

Refer the below link