Skip to Content
author's profile photo Former Member
Former Member

XML encoding using udf java code

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.

xml.png (17.2 kB)
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Jul 08, 2014 at 01:33 PM

    Hello,

    U can use XSLT mapping to convert xml string into XML structure and then map the required fields to the proxy response.

    In ur response mapping u can use xslt mapping followed by the graphical one (for mapping converted XML structure to the proxy response)

    Thanks

    Amit Srivastava

    Add a comment
    10|10000 characters needed characters exceeded

    • 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

  • author's profile photo Former Member
    Former Member
    Posted on Jul 10, 2014 at 06:11 AM

    Hi experts,

    Can someone help me with code.

    Its a priority requirement.

    Thnaks,

    chaitanya

    Add a comment
    10|10000 characters needed characters exceeded

    • 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

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.