on 12-17-2009 2:29 PM
Hello experts,
I have the following problem:
I generate a xml message with the following structure (example):
How can I realise this requirement?
Thanks and best regards!
Christopher Kühn
Hi Christopher,
Are you defining the Data type in PI? If yes then you can add the namespace while creating Message Type else if you are using XSD, then try to use XMLAnonymizerBean in your sender communication channel. You will get blogs/wiki pages on the usage of this bean
XMLAnonymizerBean
http://help.sap.com/saphelp_nw04/helpdata/en/45/d169186a29570ae10000000a114a6b/content.htm
Regards
Suraj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Christopher,
Yes that module can be used with receiver channels too (and channel in j2ee stack)
But if you want to append the namespace with receiver XML, then you can try to consider the option of XSLT of java mapping too...
Like in your operation mapping, today you have a normal mapping to convert xource XML to target XML (without namespace), you need to add one more java/xslt mapping and change this target (which is without namespace) to one with namespace... Java mapping will be the easiest one to do here..
Regards
Suraj
so I have to use the module in receiver channel. Is that also possible? I think no
Yes it is possible to use the XMLAnonymizerBean in the receiver channel......infact it is used in the receiver channel to make the namespace compatible with the receiving system.....if you still have a doubt you can refer the example in this blog where the module is used in receiver channel: /people/gabrielsagayaselvam.panneerselvam/blog/2009/12/07/standard-adapter-framework-modules-afmodules-in-pi-71-150part-1
Regards,
Abhishek.
Hi Christopher,
Call the below code as a javamappinf in the operation mapping... So now your operation mapping will have two mappings one to convert source to target XML and second this java mapping which will add namespace to your target xml
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.DynamicConfiguration;
import com.sap.aii.mapping.api.DynamicConfigurationKey;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
import com.sap.aii.mapping.api.InputHeader;
public class JavaMapping extends AbstractTransformation {
public void transform(TransformationInput arg0, TransformationOutput arg1) throws StreamTransformationException {
getTrace().addInfo("JAVA Mapping Called");
//Input payload is obtained by using arg0.getInputPayload().getInputStream()
String inData = convertStreamToString(arg0.getInputPayload().getInputStream());
String outData = inData.replaceFirst("<root>", "<root xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespace=\"http://test.de/test.xsd\">");
try
{
//8. The JAVA mapping output payload is returned using the TransformationOutput class
// arg1.getOutputPayload().getOutputStream()
arg1.getOutputPayload().getOutputStream().write(outData.getBytes("UTF-8"));
}
catch(Exception exception1) { }
}
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();
}
}
check stefans blog on the jar files that you need to make this mapping /people/stefan.grube/blog/2006/10/23/testing-and-debugging-java-mapping-in-developer-studio
Regards
Suraj
Regards
Suraj
Hello,
I have tried with the following xsl:
---
<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/root">
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespace="http://test.de/test.xsd">
<xsl:copy-of select="/root" />
</root>
</xsl:template>
</xsl:stylesheet>
-
this xsl generates the following output:
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespace="http://test.de/test.xsd">
<root>
...
</root>
</root>
how can I realise that I have only one root element?
thanks and regards
try with this XSLT....inlcude it as the very first mapping in Interface Mapping
<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespace="http://test.de/test.xsd">
<xsl:copy-of select="." />
</root>
</xsl:template>
</xsl:stylesheet>
Regards,
Abhishek.
Hi,
I solved the problem with the following xsl:
<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/root">
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespace="http://test.de/test.xsd">
<xsl:copy-of select="/root/name"/>
<xsl:copy-of select="/root/email"/>
</root>
</xsl:template>
</xsl:stylesheet>
Thanks to all for your help!
regards!
Christopher
Christopher,
XMLAnonymizerBean module can be implemented for your requirement, but it can not be implemented with XI adapter, other option would be to add namespace in XSD it self.
Try to add Namespace in xsd as per below code
<xs:schema xmlns:xs="http://www.test.org" xmlns="namespace" elementFormDefault="qualified" targetNamespace="namespace">
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.