ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » General Discussion » XML from MbElement

Post new topic  Reply to topic
 XML from MbElement « View previous topic :: View next topic » 
Author Message
goffinf
PostPosted: Sat Nov 05, 2005 12:29 pm    Post subject: XML from MbElement Reply with quote

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
View user's profile Send private message
jefflowrey
PostPosted: Sat Nov 05, 2005 12:40 pm    Post subject: Reply with quote

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
View user's profile Send private message
goffinf
PostPosted: Mon Nov 07, 2005 4:40 pm    Post subject: Reply with quote

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
View user's profile Send private message
urs
PostPosted: Mon Nov 07, 2005 4:47 pm    Post subject: Reply with quote

Acolyte

Joined: 27 Oct 2005
Posts: 56

http://www.mqseries.net/phpBB2/viewforum.php?f=7

Back to top
View user's profile Send private message Send e-mail
goffinf
PostPosted: Tue Nov 08, 2005 2:00 am    Post subject: Reply with quote

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
View user's profile Send private message
jefflowrey
PostPosted: Tue Nov 08, 2005 4:15 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » General Discussion » XML from MbElement
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.