Skip to Content

Remove special characters from XML in SAP PI

We are getting below error when Russian Cyrillic character set is present in XML/Payload

<Trace type="T" level="1">RuntimeException during appliction Java mapping com/sap/xi/tf/_MM_Mail_to_MT_PurchaseOrderMailConfirmation_IB_ Thrown: com.sap.aii.utilxi.misc.api.BaseRuntimeException: Fatal Error: com.sap.engine.lib.xml.parser.ParserException: Invalid char #0x3 (:main:, row:1, col:100)at com.sap.aii.mappingtool.tf7.Transformer.checkParserException(Transformer.java:206)at com.sap.aii.mappingtool.tf7.Transformer.start(Transformer.java:160)at com.sap.aii.mappingtool.tf7.AMappingProgram.transform(AMappingProgram.java:698)at com.sap.aii.ib.server.mapping.execution.JavaMapping.executeStep(JavaMapping.java:112)

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    Posted on Mar 31 at 02:38 AM

    We have used below code to resolved the issue

    import java.io.InputStream;
    
    
    import java.io.*;
    import com.sap.aii.mapping.api.AbstractTransformation;
    import com.sap.aii.mapping.api.StreamTransformationException;
    import com.sap.aii.mapping.api.TransformationInput;
    import com.sap.aii.mapping.api.TransformationOutput;
    
    
    
    
    public class Convert_to_UTF8  extends AbstractTransformation {
    	@Override
    	public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException {
    		try { 
    			String content="";
    			String line = ""; 
    			int l;
    			InputStream ins = in.getInputPayload().getInputStream(); 
    			BufferedReader br = new BufferedReader( new InputStreamReader(ins,"UTF-8")); 
    		while ((l = br.read()) != -1) 
    		{
    			if((l>31 && l<127) || (l>159))
    			line+=(char) l;
    			
    		}
    		br.close();
    		content+= line+'\n';
    		out.getOutputPayload().getOutputStream().write(content.getBytes("UTF-8"));
    			
    		 
    		}
    		catch (Exception e) { throw new StreamTransformationException(e.getMessage()); } 
    			
    	
    	}
    }
    
    
    
    Add a comment
    10|10000 characters needed characters exceeded