on 03-01-2011 1:51 PM
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
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
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.