Author |
Message
|
goffinf |
Posted: Thu Sep 13, 2007 9:28 am Post subject: Creating a string from a message tree fragment in Java |
|
|
Chevalier
Joined: 05 Nov 2005 Posts: 401
|
I want to be able to access a part of a message passed into a JavaCompute node, turn it into a string and pass it to some external Java code. I tried something along the lines of the attached but it appears (?) from the help that the toBitStream method of MbElement will only operate on the message body itself.
[quote}Returns the bit stream representation of the element. This method causes the parser associated with the element to serialize the element and all its children. This method can only be called on the message body, i.e. the last child of the message root.[/quote]
Is there another way I can do this ?
Regards
Fraser.
public void evaluate(MbMessageAssembly contact admin) throws MbException {
MbMessage inMessage = contact admin.getMessage();
...
MbElement inMessageRoot = inMessage.getRootElement();
MbElement inboundmessageParser = inMessageRoot.getLastChild();
....
// navigate to the root element of the message body
MbElement MBServiceWrapper = inboundmessageParser.getLastChild();
// navigate to the part that Im interested in
MbElement originalXMLInstance = MBServiceWrapper.getFirstElementByPath("requestPayload/originalXMLInstance").getFirstChild();
// Now turn this into a String
// this fails
byte[] originalXMLbytes = originalXMLInstance.toBitstream(null, null, null, 0, 1208, 0);
// I was intending to do this next
String originalXMLString = null;
originalXMLString = new String(originalXMLbytes, "ascii"); |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Sep 13, 2007 9:31 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Do you want a serialization of a subtree?
Or only the VALUE of a particular MbElement? _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
goffinf |
Posted: Thu Sep 13, 2007 9:32 am Post subject: |
|
|
Chevalier
Joined: 05 Nov 2005 Posts: 401
|
The complete subtree below the MbElement reference |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Sep 13, 2007 9:32 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Does toBitstream throw an exception? _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
goffinf |
Posted: Thu Sep 13, 2007 9:38 am Post subject: |
|
|
Chevalier
Joined: 05 Nov 2005 Posts: 401
|
Yes, a nested parser exception which says :-
- XML writing errors have occurred
- No valid body of the document could be found |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Sep 13, 2007 9:41 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Okay. You can try figuring out what the value of the ESQL constant "FolderBitStream" as passed to the ASBITSTREAM function is, and pass that to toBitstream in the options parameter.
It might not work.
You can also use MbSQLStatement to call ASBITSTREAM from Java, I believe. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
|