|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
XML from MbElement |
« View previous topic :: View next topic » |
Author |
Message
|
goffinf |
Posted: Sat Nov 05, 2005 12:29 pm Post subject: XML from MbElement |
|
|
Chevalier
Joined: 05 Nov 2005 Posts: 401
|
Using WBIMb v5.1
I want to load the contents of an MbElement (containing the global Environment) into a DOM, but I can't seem to get the required XML (string) representation. Does anyone know if this is possible and can suggest a method. This is what I have been trying with not much success :-
public Vector doStuff(MbMessageAssembly contact admin) throws MbException {
//get Local Env
String mbXML = null;
MbMessage localMessage = contact admin.getGlobalEnvironment();
MbElement localRoot = localMessage.getRootElement();
// OK so far
try {
/* This blows with a contact admin BIPBroker exception
[BIPv500:2111]BIP2111E: Message broker internal error: diagnostic information '{0}' ....
*/
mbXML = new String(localMessage.getBuffer());
/* This doesn't blow but doesn't contain what I want
mbXML = new String(contact admin.getMessage().getBuffer());
*/
Thanks
Fraser. |
|
Back to top |
|
 |
jefflowrey |
Posted: Sat Nov 05, 2005 12:40 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Okay, you really should have posted this in the WBIMB forum, not here.
Second of all...
If you want to get the entire contents of a tree or subtree as a bitstream, use ASBITSTREAM.
Thirdly, if you want to get the value of an MbElement, then use getValue.
Fourthly, it seems fairly unlikely that you need to be using the Java API at all. If you can be more specific about what you are trying to do, we can probably direct you to a better way to do it. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
goffinf |
Posted: Mon Nov 07, 2005 4:40 pm Post subject: |
|
|
Chevalier
Joined: 05 Nov 2005 Posts: 401
|
Thanks Jeff.
I didn't know there was a WBIMB forum can you supply a URL ?
What I'm actually up to is :-
Some time ago we created a custom node to provide a slightly richer implementation of the MB Transform node. Our one allows parameters to be passed into the XSLT.
I want to pass a parameter that is an XML fragment to the XSLT and this fragment is actually part of the global Environment.
So basically I was intending to extract the XML from the Environment, load it into a DOM and pass it into the Xalan parser using setParamter.
This is the first part of the code in the custom node :-
MbMessage localMessage = contact admin.getGlobalEnvironment();
MbElement localRoot = localMessage.getRootElement();
I am guessing from your reply that if I want an XML representation of localRoot I would need to do something like this ? :-
byte[] bs = localRoot.toBitstream(null,null,null,0,1208,0);
String mbXML = new String(bs, "UTF-8");
Then later on I load up (mbXML) into a DOM (paramDoc) and set the parameter on the transformer like this :-
Transformer transformer = null;
TransformerFactory tFactory = TransformerFactory.newInstance();
transformer = tFactory.newTransformer(new StreamSource(xslFilename));
transformer.clearParameters();
// set the param
transformer.setParameter("inboundXML", paramDoc.selectSingleNode("/some-XPath-expression"));
and finally execute the tranform itself :-
transformer.transform(new DOMSource(doc), new StreamResult(baos));
What do you think ??
Fraser. |
|
Back to top |
|
 |
urs |
Posted: Mon Nov 07, 2005 4:47 pm Post subject: |
|
|
Acolyte
Joined: 27 Oct 2005 Posts: 56
|
|
Back to top |
|
 |
goffinf |
Posted: Tue Nov 08, 2005 2:00 am Post subject: |
|
|
Chevalier
Joined: 05 Nov 2005 Posts: 401
|
Actually I now have another problem with toBitstream. Below is the code snippet which is failing, and this is what is output to the logger :-
localRoot FirstChild name is : Lookup. <-- this confirms what I expect to be in the Environment
[BIPv500:5010]BIP5010E: XML Writing Errors have occurred. Errors have occurred during writing of XML. Review further error messages for an indication to the cause of the errors. : XML Writing Errors have occurred.
public Vector getParameters(MbMessageAssembly contact admin) throws MbException {
//get Local Env
String message = null;
String mbXML = null;
MbMessage localMessage = contact admin.getGlobalEnvironment();
MbElement localRoot = localMessage.getRootElement();
MbElement variables = localRoot.getFirstElementByPath(variablesRoot);
try {
Logger.log(node, "About to try creating a string");
// Just checking there is what I expect in the Environment
Logger.log(node,"localRoot FirstChild name is : " + localRoot.getFirstChild().getName());
// BLOWS ON THE NEXT LINE ??
byte[] bs = localRoot.getFirstChild().toBitstream("","","",0,0,0);
//byte[] bs = localRoot.getFirstChild().toBitstream(null,null,null,0,1208,0);
Logger.log(node, "Byte stream created. Converting to string");
mbXML = new String(bs, "ascii");
Logger.log(node, "mbXML: " + mbXML);
} catch (Exception e) {
Logger.log(node, e.getMessage());
}
... |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue Nov 08, 2005 4:15 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
toBitstream has some caveats in the Javadoc about when it is usable and when it isn't.
And toBitstream is not the same as ASBITSTREAM. One is Java, the other is ESQL. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|