cancel
Showing results for 
Search instead for 
Did you mean: 

xml payload encoding from utf to iso

former_member210677
Participant
0 Kudos

Hi Experts,

Could you please let me know how can I encode he xml payload from utf-8 to ISO-8859-1.

its bit urgent any help is appreciated.

Thanks & Regards,

Ranganath.

Accepted Solutions (0)

Answers (3)

Answers (3)

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

You can try using the TextCodepageConversionBean for your requirement

http://help.sap.com/saphelp_nwpi711/helpdata/en/84/2e3842cd38f83ae10000000a1550b0/frameset.htm

Hope this helps,

Mark

stefan_grube
Active Contributor
0 Kudos

> You can try using the TextCodepageConversionBean for your requirement

Sorry Mark,

this bean must not be used for XML.

markangelo_dihiansan
Active Contributor
0 Kudos

Thanks Stefan! I guess I have to read your H2G

Regards,

Mark

anupam_ghosh2
Active Contributor
0 Kudos

Hi Ranganath,

Here is the java mapping for PI 7.1 and above which will transform encoding type from utf-8 to ISO-8859-1.


import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;


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 addAttributeToTag2 extends AbstractTransformation {

	/**
	 * @param args
	 */
	

	public void execute(InputStream in, OutputStream out)
			throws StreamTransformationException {
		// TODO Auto-generated method stub
		try
		{
			int c;
			int count=0;
			String s="";
			while(1>0)
			{	
				
				c=in.read();
				if(c<0)
				{
					break;
				}
				if(count<=2 && (char)c=='?')
				{
					count++;
				}
				if(count<=2)
				{
					
					s=s+(char)c;
					if(count==2)
					{
						s=s.replaceAll("utf-8","ISO-8859-1");
						s=s.replaceAll("UTF-8","ISO-8859-1");
						count=3;
						out.write(s.getBytes());
					}
					continue;
				}
				out.write(c);
				//System.out.print((char)c);
			}
			in.close();
			out.close();
		}	
		catch(Exception e)
		{
		}	
		
	}

	public void setParameter(Map arg0) {
		// TODO Auto-generated method stub
		
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try{
			addAttributeToTag2 genFormat=new addAttributeToTag2();
			FileInputStream in=new FileInputStream("C:\\Apps\\my folder\\sdn\\copy.xml");
			FileOutputStream out=new FileOutputStream("C:\\Apps\\my folder\\sdn\\copy1.xml");
			genFormat.execute(in,out);
			}
			catch(Exception e)
			{
			e.printStackTrace();
			}
	}

	public void transform(TransformationInput arg0, TransformationOutput arg1)
			throws StreamTransformationException {
		this.execute(arg0.getInputPayload().getInputStream(), arg1.getOutputPayload().getOutputStream());
		
	}
}


if you are working in PI 7.0 the you need following code


import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;


import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;


public class addAttributeToTag2 implements StreamTransformation {

	/**
	 * @param args
	 */
	

	public void execute(InputStream in, OutputStream out)
			throws StreamTransformationException {
		// TODO Auto-generated method stub
		try
		{
			int c;
			int count=0;
			String s="";
			while(1>0)
			{	
				
				c=in.read();
				if(c<0)
				{
					break;
				}
				if(count<=2 && (char)c=='?')
				{
					count++;
				}
				if(count<=2)
				{
					
					s=s+(char)c;
					if(count==2)
					{
						s=s.replaceAll("utf-8","ISO-8859-1");
						s=s.replaceAll("UTF-8","ISO-8859-1");
						count=3;
						out.write(s.getBytes());
					}
					continue;
				}
				out.write(c);
				//System.out.print((char)c);
			}
			in.close();
			out.close();
		}	
		catch(Exception e)
		{
		}	
		
	}

	public void setParameter(Map arg0) {
		// TODO Auto-generated method stub
		
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try{
			addAttributeToTag2 genFormat=new addAttributeToTag2();
			FileInputStream in=new FileInputStream("C:\\Apps\\my folder\\sdn\\copy.xml");
			FileOutputStream out=new FileOutputStream("C:\\Apps\\my folder\\sdn\\copy1.xml");
			genFormat.execute(in,out);
			}
			catch(Exception e)
			{
			e.printStackTrace();
			}
	}
}


However as Krish has pointedf out file adapter has option to set encoding type, you can try that option first.

regards

Anupam

stefan_grube
Active Contributor
0 Kudos

PLEASE do not provide such code.

You cannot just change the encoding declaration without changing the encoding of the characters too.

There are different ways to change the ecoding, depending on the scenario and the adapters used.

See my H2G:

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/502991a2-45d9-2910-d99f-8aba5d79f...

former_member210677
Participant
0 Kudos

HI Krish/Anupam,

I did try using the encoding format from utf-8 to ISO using file type in receiver file adapter, but couldn't get the expected result. Here i should convert the idoc xml which is in utf-8 format to ISO-8859-1 to file xml format. So please let me know for any other option in PI 7.0 file adapter.

thanks & regards,

Ranganath.

stefan_grube
Active Contributor
0 Kudos

In receiver file adapter you can change the encoding of your XML with help of the XMLAnonymizerBean

You can use a simple XSLT also.

anupam_ghosh2
Active Contributor
0 Kudos

Hi Stefan,

I went through the link. Thank you for pointing out the error.

I need to convert the the encoding of characters within the XML.

Hi Ranganath,

Please ignore my previous post. Please consult the H2G provided by Stefan, it contains java mapping code which fits your requirement.

regards

Anupam

Edited by: anupamsap on Oct 26, 2011 1:42 PM

former_member210677
Participant
0 Kudos

thank you for the information stefen...I hope XML bean should help in rectifying the issue.....

Former Member
0 Kudos

Hi Ranganath,

What exactly is your requirement? XML encoding is normally provided in the file adapter where you specify whether ISO or UTF-8.

Where exactly do you want to use this encoding? Please explain a bit more.

Regards

Krish