cancel
Showing results for 
Search instead for 
Did you mean: 

Handling Character Entities - Java Mapping Issue

Former Member
0 Kudos

Hi Experts,

I need to replace the character entities in my input XML. But, the problem is the java mapping I've written isn't replacing the character entities as expected. For example if my input XML contains <NAME>&><XYZ</NAME>, then the ouput is <NAME>&amp:&gt:<0001&lt:/NAME>, whereas it should be <NAME>&amp:&gt:&lt:0001</NAME>.

Note: I've used : instead of ; just to show it properly SDN.

Can any of you share the code for the same if you've used it already?

Thanks a lot in advance.

Regards,

Hussain.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Please see this[ blog|http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=(J2EE3417500)ID1284776550DB10026887333321355037End?blog=/pub/wlg/9420] for handling & in java mapping ,in fact its written by pooja itself:).

also please have a look at this[ thread |;for some code snippets, to be specific. try out kenny's reply.

regards,

srinivas

Former Member
0 Kudos

Are you trying to use the java mapping just to handle the character entities or your interface itself only has a java mapping?

In the message mapping, you wont be having any problem in handling the < > characters if they are coming in &gt ;&l t; form.

Former Member
0 Kudos

Hi Pooja,

Thanks for your prompt reply.

Are you trying to use the java mapping just to handle the character entities or your interface itself only has a java mapping?

- I'm using Java Mapping just to handle the character entities. Say my input XML looks like

<?xml version="1.0" encoding="UTF-8"?>

<resultset>

<row>

<ID>&<1</ID>

<MESSAGE><![CDATA[<?xml version="1.0" encoding="UTF-8" ?><LGORT>&<0001</LGORT>]]></MESSAGE>

</row>

</resultset>

I need to replace &< in <ID> to &amp:&lt: and similarly for CDATA <LGORT>&amp:&lt:0001</LGORT> before I process it in XI. In my java mapping I read the whole XML as string (line by line as mentioned below) and try to replace the character entities using some logic, which isn't working properly.

StringBuffer buffer = new StringBuffer();

BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));

for (String lineRead = reader.readLine(); lineRead != null; lineRead = reader.readLine()) {

buffer.append(lineRead);

}

I've also checked the thread mentioned by Srinivas. But, StringEscapeUtils.escapeXml() would replace all the character entities like &lt:?XML... , which would result in an invalid xml...

Please suggest.

Thanks,

Hussain.