(WMB) Printing XML in JavaCompute

Printing application data in xml format in Java compute node is bit tricky, If we simply print the body (payload) we will not have data in xml format. We have to make use of toBitstream method to convert the body into an array of bytes & then print.

Excerpt of evaluate method :

  MbMessage message = assembly.getMessage();
MbElement root = message.getRootElement();
MbElement body = root.getLastChild();
byte[] b = null;
b = body.toBitstream("", "", "", 0, 0, 0);
 // This example is taken with XMLNSC as parser for input so no need to specify messageType, messageSet & wire format. 
 //For MRM parser, these parameters has to be specified.

try {
ByteArrayInputStream arrayInputStream = new ByteArrayInputStream(b);
InputStreamReader inputStreamReader = new InputStreamReader(arrayInputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
char[] c = new char[b.length];
bufferedReader.read(c, 0, c.length);
System.out.println(c);
} catch (Exception e) {
e.printStackTrace();
}

Signature of toBitstream method :
                  
public byte[] toBitstream(String messageType, String messageSet, String messageFormat,int encoding,int ccsid, int options) throws MbException

1 comment: