cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert Special charachter in SAP PI

former_member190358
Participant
0 Kudos

Hi SAP PI Team,

I am working on SAp PI 7.31 single stack .

I have a requirement to convert the special character into entity reference as seen below.

Name

Character

Entity Ref

Quotation mark

&quote;

Ampersand

&

&

Apostrophe

'

Less than sign

<

&it;

Greater than sign

>

&gt;

Could you please check and let me know if i will have to parse the entire xml or is there any other way to achieve this.

Regards

Ravi

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

If you want to remove only single special character / only 5 characters as you listed use "Replace string" function.

If you want to remove multiple special characters use below UDF.

String result = "";

String[] splt;

delimiter = "'"; //special character to be removed

splt = input.split(delimiter);

for(int i =0; i < splt.length ; i++)

       result = result + splt(i);

Regards,

Neelima.

stefan_grube
Active Contributor
0 Kudos

Could you describe the whole scenario?

Why you want to replace the characters and how should the output look like?

When you replace < and > with entity reference, then the output is no valid XML, is this what you expect?

former_member190358
Participant
0 Kudos

Hi Stefan,

The input  looks like this as seen below :

And the required output should be as seen below :

Regards

Ravi

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Ravi,

It is just the xml parser escaping it to an &, right-click on the payload and then select view source and you will see it is really &amp; .

Regards,

Mark

Former Member
0 Kudos

Hi Ravi,

I think you need to use UDF code to achieve your requirement.

1. Write the udf code to check the symbol in input string, it it found pass the value as required.

Thanks,

Satish.

Former Member
0 Kudos

Hi Ravi,

We usually create a Java mapping and parse the input payload for handling the special characters.

You might want to use the SAX parser, see link below:

XML parsing using SaxParser with complete code | Java Code Geeks

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Ravi,

Can you view these characters in IE properly? If yes, then it means they are already escaped. Right-click on the payload and select view source you will see that " is really &quote; in notepad.

If you want to convert everything in the XML to its entity ref, you have to parse it though.

Regards,

Mark