Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

SAP PI - Deciphering apostrophes in XML.

Link to Content's target Space : 

Applies to:

SAP PI 7.1/7.0.


This article explains how to handle special characters in file based scenarios using simple mapping programs


Sreehari Nambiar   
Company:     Deloitte Consulting
Created on:    September 2, 2011
Author(s) Bio
Sreehari, currently working with Deloitte Consulting, is a certified SAP PI consultant with sound ABAP knowledge


This interface is an ABAP proxy to XML file scenario. The XML file was generated and sent to the legacy system. However, the file failed initial validations. Reason - the field EventCode in the target contained unwanted characters (') which the legacy system could not interpret


In the first look, everything looked good in PI. The XML, post mapping step had no junk characters. Similarly, the XML file viewed using Internet Explorer also had correct data.

 Lord Google told us that ''' is nothing but "XML Representation of apostrophes"
 This prompted us to take a look at the XML in raw format. And there we got hold of the culprit - XML parsing.

The XML parsing that happens during graphical mapping converted the apostrophe into '''. So the obvious solution was to avoid the parsing. 


This was achieved by a java mapping which transferred the the source XML as a stream to the target and while doing so, replacing the "&asos;" back to normal aposotrophe.The Java Mapping was called after the first (graphical mapping) which had the transformation rules as per business.

Note: Similar approach could be used for other XML characters as well. The XML file when viewed in Internet Explorer or the Graphical Mapping output, will display Apostrophes correctly. Only when you view the XML file as a raw text, these special characters are displayed as per XML standards  

Java Code


public class JMap extends AbstractTransformation
{     public void transform(TransformationInput in, TransformationOutput out)
	  throws StreamTransformationException {
				  InputStream is = in.getInputPayload().getInputStream();
				  OutputStream os = out.getOutputPayload().getOutputStream();
				  long length = is.available();
				  byte[] bytes = new byte[(int) length];;
				  String cleanXMLString = null;
				  cleanXMLString =new String(bytes).replaceAll("'","'");
			catch (Exception ex){