cancel
Showing results for 
Search instead for 
Did you mean: 

Java Mapping JDBC ResultSet to XML

Former Member
0 Kudos

Hi All

In my java mapping I call a stored procudere that returns a result set, now I what to convert the result set to XML and parse it back to the mapping.I'm able to loop throug the result set and with getTrace().addInfo I can see the values. Anyone know how I can get this into XML?

Regards

Accepted Solutions (0)

Answers (3)

Answers (3)

baskar_gopalakrishnan2
Active Contributor
0 Kudos

If you are using SAP PI 7.1 you need to use method name as follows

public void transform(TransformationInput input, TransformationOutput output)
    throws StreamTransformationException
  {

if Pi 7.0  then method name as follows

public void execute(InputStream in, OutputStream out)
    throws StreamTransformationException  {

// inside try block

try{
     DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
     dbf.setNamespaceAware(true);
     DocumentBuilder builder = dbf.newDocumentBuilder();
     Document doc = null;
       // Reading a XML file	
      doc = builder.parse(in);
      doc.getDocumentElement().normalize();
      Element root =  doc.getDocumentElement().getNodeName();
     // Like wise you can navigate to any of your input xml tag elements and insert the value of your resultset in the xml instance
}

Former Member
0 Kudos

This is another way . Using DOM parser ..

Using their Methods like

createElement,

appendChild

you can create your target XML and then similarly Pass it out , the same way .. in Execute method .

Former Member
0 Kudos

What Version are U using .

if it PI 7.0 , PI 7.1 has Different API ( transform)

There is a mathod called EXECUTE

public void execute(InputStream input, OutputStream output) throws StreamTransformationException

{

}

Now This output Object is used to set Output XML values for Target .

Now Create a String S variable with your TARGET XML Structure .

and Out it like

output.write(S.getBytes());

your S structure Should be like this

S = "<TargetMT><ResultSet>Value1</ResultSet><ResultSet>Value1</ResultSet></TargetMT>"

Use your Loop to populate value in <ResultSet> and Pass it outside using output.write(S.getBytes());

Here Created S is Just an example Stucture . .. you create your Similar to your Target DT/MT.

Hope This Helps