on 07-08-2014 2:21 PM
Hi Experts,
we are working on SAP PI version 7.0.
We are getting a SOAP response from 3rd party system.. as per below screen shot.
We need to read the data in field "DATA"and we have to send same data as request to ECC through proxy.
please suggest the java mapping code to read the XML file data which is present in the "DATA" field and parse it to target structure.
please let me know if any info required.
Thanks in advance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
It's a straight forward XSLT, not sure where u are struggling?
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<xsl:value-of select="//Data" disable-output-escaping="yes"/>
</xsl:template>
</xsl:stylesheet>
Note - adjust namespaces according to ur structure
Thanks
Amit Srivastava
Hi Amit,
I have tried with the XSL code and its generating the XML structure as per the data maintained in the "Data" field.
The problem is, the input structure is static and the data present in the "Data" field is dynamic.
The output XML structure is getting generated with the data present in the "Data" field properly as per the provided screenshot.
I cant send the same output different XMl structures to ECC as there should be fixed structure in the proxy to be written.
Could you please provide me the code which will create the Message Type with the namespace, so that i can use the same in the next message mapping after the XSLT mapping and do the necessary modifications.
Regards,
Chaitanya
Hello,
U need a little bit of adjustment in xslt , check below code
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:ns0="http://test" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<ns0:MT_Name>
<xsl:variable name="data">
<xsl:value-of select="substring(//Data, 39)"/>
</xsl:variable>
<xsl:value-of select="$data" disable-output-escaping="yes"/>
</ns0:MT_Name>
</xsl:template>
</xsl:stylesheet>
Thanks
Amit Srivastava
Hi experts,
Can someone help me with code.
Its a priority requirement.
Thnaks,
chaitanya
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is the Java Mapping code
package ia_getcdata;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.CharacterData;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
public class ExtractData implements StreamTransformation {
public void setParameter(Map arg0) {
}
public void execute(InputStream in, OutputStream out) throws StreamTransformationException {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(in);
NodeList nLData = doc.getElementsByTagName("Data");
Node nData = nLData.item(0);
Node child = nData.getFirstChild();
CharacterData cd = (CharacterData)child;
String dataString = cd.getData();
out.write(dataString.getBytes("UTF-8"));
}
catch (Exception e) {
e.printStackTrace();
}
}
}
Of course this is unoptimized, but it will work for your requirement.
Regards,
Mark
Hi Mark,
I have tried with the java mapping provided by you and its get worked as per requirement..
Thanks alot for the response .
The problem is, the input structure is static and the data present in the "Data" field is dynamic.
The output XML structure is getting generated with the data present in the "Data" field properly as per the provided screenshot.
I cant send the same output different XMl structures to ECC as there should be fixed structure in the proxy to be written.
Could you please provide me the code which will create the Message Type with the namespace, so that i can use the same in the next message mapping after the java mapping and do the necessary modifications.
Regards,
Chaitanya
Hi,
Sorry for the late response. Here is the new code:
package ia_getcdata;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.CharacterData;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
public class ExtractData implements StreamTransformation {
/**
@see com.sap.aii.mapping.api.StreamTransformation#setParameter(Map)
*/
public void setParameter(Map arg0) {
}
public void execute(InputStream in, OutputStream out) throws StreamTransformationException {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(in);
NodeList nLData = doc.getElementsByTagName("Data");
Node nData = nLData.item(0);
Node child = nData.getFirstChild();
CharacterData cd = (CharacterData)child;
String dataString = cd.getData();
dataString = dataString.substring(dataString.indexOf("?>")+2);
out.write("<YourMessageTypeHere>".getBytes("UTF-8"));
out.write(dataString.getBytes("UTF-8"));
out.write("</YourMessageTypeHere>".getBytes("UTF-8"));
}
catch (Exception e) {
e.printStackTrace();
}
}
}
Hope this helps,
Mark
User | Count |
---|---|
84 | |
10 | |
10 | |
9 | |
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.