on 10-26-2011 8:21 AM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
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.
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.