Java WebService adding CDATA field in response



I'm working on a webservice where, i created the wsdl and generated the java classes using apache axis2.


The problem I'm trying to solve is, while creating web service response I have to set text with special characters like Books & Pens Or Value is <10> in some of the fields. I am looking for ways to just put these field content in CDATA sections.


Example response my WebService has to send:



<BOOKSHOP>
<ITEM><![CDATA[BOOKS & PENS]]></ITEM>
</BOOKSHOP>


I'm not able to find a way to do this. I have googled but found no solution.


Any help would be really appreciated.


I'm aware of converting these special characters explicitly into



& amp ; or & lt;

but that does not work for us. Also, We want to put just the required fields in CDATA and not entire XML response. I tried @XmlCDATA but it works only if my text is XML structured.

No comments:

Post a Comment