on 11-26-2009 8:29 AM
Hi,
Is it possible to remove xml encoding?
From
<?xml version="1.0" encoding="UTF-8"?>
To
<?xml version="1.0"?>
Hi Gautam,
I have tried XMLAnonymizerBean before. It actually can remove namespaces and changed encoding. But it can't remove encoding. Thanks for your reply.
Hi Suraj,
Thanks for your reminded. But our vendor don't want the encoding in xml declaration when they get the xml message. I have no choice. Or has any other way, no impact on data, can remove encoding?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sander,
Try this java mapping it shoudl work
PS: I am hoping that you are in PI7.1 .. you need to import com.sap.xpi.ib.mapping.lib.jar file
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
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;
/**
* @author srsuraj
*
*/
public class GetContent extends AbstractTransformation {
public void execute(InputStream in, OutputStream out)
throws StreamTransformationException {
// Add your code here
String inData = convertStreamToString(in);
String outData = inData.replaceFirst("encoding=\"UTF-8\"","");
try
{
//The JAVA mapping output payload is returned using the TransformationOutput class
// arg1.getOutputPayload().getOutputStream()
out.write(outData.getBytes("UTF-8"));
}
catch(Exception exception1) { }
}
//Un comment to test the mapping as a standalone code
/*public static void main(String[] args) {
try {
//InputStream in = new FileInputStream(new File("C:\\Suraj\\eclipse-jee-ganymede-SR2-win32\\Workspace\\JavaMapping\\in.txt"));
InputStream in = new FileInputStream(new File("C:\\Suraj\\eclipse-jee-ganymede-SR2-win32\\Workspace\\JavaMapping\\test.xml"));
OutputStream out = new FileOutputStream(new File("out.xml"));
GetContent myMapping = new GetContent();
myMapping.execute(in, out);
} catch (Exception e) {
e.printStackTrace();
}
}*/
public void transform(TransformationInput arg0, TransformationOutput arg1) throws StreamTransformationException {
getTrace().addInfo("JAVA Mapping Called");
this.execute(arg0.getInputPayload().getInputStream(),
arg1.getOutputPayload().getOutputStream());
}
public String convertStreamToString(InputStream in){
StringBuffer sb = new StringBuffer();
try
{
InputStreamReader isr = new InputStreamReader(in);
Reader reader =
new BufferedReader(isr);
int ch;
while((ch = in.read()) > -1) {
sb.append((char)ch);}
reader.close();
}
catch(Exception exception) { }
return sb.toString();
}
}
Regards
Suraj
Hi Suraj,
Your java mapping is ok and solved my issue. Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Thank you all.
I have tried the XSLT but it didn't work.The encoding still stick with xml declaration.
I will try the java mapping. Do you have any idea about this?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sander,
You can easily achieve this using JAVA Mapping. I was wondering though if xmlanonymizerbean can be used for this purpose.
It can be used to remove namespaces, but I am not sure about removing xml encoding.
I was going through the below blog when I read your thread;
[http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=(J2EE3417100)ID0592847450DB01542092484904114753End?blog=/pub/wlg/5767|XMLAnonymizerBean by Stefan Grube]
(P.S: Din't intend to distract you but just thought this may help in some way.)
(Dont know why I am not able to post the link, you can search for blog Remove namespace prefix with XMLAnonymizerBean by Stefan Grube)
Regards,
Gautam Purohit
Edited by: Gautam Purohit on Nov 26, 2009 6:20 PM
Hi Sander,
>>I will try the java mapping. Do you have any idea about this?
Removing the encoding from xml tag will be acheivedby java mapping.. but because of this removal make sure you will not have any impact in the data (as i have mentioned in my first thread that it is this encoding that decides the contents encoding)
Regards
Suraj
Try this XSL mapping...
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0"/>
<xsl:template match="/">
<xsl:copy-of select="/child::node() "/>
</xsl:template>
</xsl:stylesheet>
though we are not specifying any encoding in <xsl:output> I guess by default it would make it as UTF-8.
~SaNv...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Check page 7 of this document:
Regards,
Abhishek.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Suraj,
Thanks for your reply.
What's the java mapping you mention? Is the UDF in the message mapping or Java bean on the adapter module?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Java mapping is a type of message mapping available in PI. Check this link http://help.sap.com/saphelp_nw04/helpdata/en/e2/e13fcd80fe47768df001a558ed10b6/frameset.htm
You use it with interface mapping..
For sample code check wiki page: http://wiki.sdn.sap.com/wiki/display/XI/SampleJAVAMappingcodeusingPI7.1+API
Regards
Suraj
Hi Sander,
YEs use java mapping and remove it...
But before that check this
If no encoding attribute is specified, then the XSLT processor should use either UTF-8 or UTF-16. It is possible that the result tree will contain a character that cannot be represented in the encoding that the XSLT processor is using for output. In this case, if the character occurs in a context where XML recognizes character references (i.e. in the value of an attribute node or text node), then the character should be output as a character reference; otherwise (for example if the character occurs in the name of an element) the XSLT processor should signal an error.
taken from http://www.w3.org/TR/xslt#output
So I would suggest you to convert the encoding to any format you require and that can be done by XSLT mapping like
<?xml version="1.0" ?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output encoding="urencoding"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Regards
Suraj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
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.