Skip to Content
0
Former Member
Jun 29, 2012 at 02:12 AM

Parsing Special characters in XML using JAVA Code in SAP PI

949 Views

Hi All,

I have an issue parsing 5 special characters ie ("Á,Ï,Í,Ð,Ÿ) beause of these 5 characters the xml is unable to parse them

It works fine with graphical mapping "replace string" function...but I want to go with Java mapping, UDF

Can someone guide me if this code is correct

public class UTFISO implements StreamTransformation {

private final String l = "Á,Ï,Í,Ð,Ÿ";

private final String u ="A,I,I,D,Y";

public void execute(InputStream in, OutputStream out) {

try {

DataInputStream stdin = new DataInputStream(in);

int length = getLengthFromStream(stdin);

stdin.reset();

byte[] buffer = getBytesFromStream(stdin);

String str = new String(buffer, u);

str = str.replaceAll(u, l);

out.write(str.getBytes(l));

out.close();

} catch (IOException e) {

}

}

Also tried with code

String s = "";

String a = "";

s = a.replace("Á" , "A");

return s;

but this returns a empty or what ever value i give it to string ,but I need at runtime to capture the incomming value and if any special charecter is found replace it