|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Convert Environment Tree to a string... |
« View previous topic :: View next topic » |
Author |
Message
|
EKhalil |
Posted: Fri Nov 04, 2011 6:47 pm Post subject: Convert Environment Tree to a string... |
|
|
Voyager
Joined: 29 Apr 2003 Posts: 99 Location: Boston, MA
|
This works on the message tree only:
byte [] msgAsBytes = outMessage.getRootElement().getLastChild().toBitstream(null,null,null,0,0,0);
String msgAsText = new String(msgAsBytes);
messageAug.createElementAsFirstChild(MbElement.TYPE_NAME_VALUE,"EVA", msgAsText);
So to get environment tree into a string I wrote this:
MbMessage environment = contact admin.getGlobalEnvironment();
MbElement variables = environment.getRootElement().getFirstChild();
MbElement variablesPosition = variables.getFirstChild();
StringBuffer strBufferEnv = new StringBuffer();
for (int s = 0; variablesPosition != null; s++) {
strBufferEnv.append("<");
strBufferEnv.append(variablesPosition.getName());
strBufferEnv.append(">");
if (variablesPosition.getValueAsString() != null) {
strBufferEnv.append(variablesPosition.getValueAsString());
}
else{
MbElement variablesPosition2 = variablesPosition.getFirstChild();
if (variablesPosition2 != null){
for (int t = 0; variablesPosition2 != null; t++) {
strBufferEnv.append("<");
strBufferEnv.append(variablesPosition2.getName());
strBufferEnv.append(">");
if (variablesPosition2.getValueAsString() != null) {
strBufferEnv.append(variablesPosition2.getValueAsString());
}
else{
MbElement variablesPosition3 = variablesPosition2.getFirstChild();
if (variablesPosition3 != null){
for (int u = 0; variablesPosition3 != null; u++) {
strBufferEnv.append("<");
strBufferEnv.append(variablesPosition3.getName());
strBufferEnv.append(">");
if (variablesPosition3.getValueAsString() != null) {
strBufferEnv.append(variablesPosition3.getValueAsString());
}
else{
MbElement variablesPosition4 = variablesPosition3.getFirstChild();
if (variablesPosition4 != null){
for (int v = 0; variablesPosition4 != null; v++) {
strBufferEnv.append("<");
strBufferEnv.append(variablesPosition4.getName());
strBufferEnv.append(">");
if (variablesPosition4.getValueAsString() != null) {
strBufferEnv.append(variablesPosition4.getValueAsString());
}
strBufferEnv.append ("</");
strBufferEnv.append(variablesPosition4.getName());
strBufferEnv.append(">");
variablesPosition4 = variablesPosition4.getNextSibling();
}
}
}
strBufferEnv.append ("</");
strBufferEnv.append(variablesPosition3.getName());
strBufferEnv.append(">");
variablesPosition3 = variablesPosition3.getNextSibling();
}
}
}
strBufferEnv.append ("</");
strBufferEnv.append(variablesPosition2.getName());
strBufferEnv.append(">");
variablesPosition2 = variablesPosition2.getNextSibling();
}
}
}
strBufferEnv.append ("</");
strBufferEnv.append(variablesPosition.getName());
strBufferEnv.append(">");
variablesPosition = variablesPosition.getNextSibling();
}
String Eva2 = strBufferEnv.toString();
messageAug.createElementAsFirstChild(MbElement.TYPE_NAME_VALUE,"EVA2", Eva2);
Which works just fine...but Im wondering if there is any better way to do this in JCN ? |
|
Back to top |
|
 |
rekarm01 |
Posted: Sat Nov 05, 2011 11:44 am Post subject: Re: Convert Environment Tree to a string... |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 1415
|
EKhalil wrote: |
This works on the message tree only:
Code: |
byte [] msgAsBytes = outMessage.getRootElement().getLastChild().toBitstream(null,null,null,0,0,0);
String msgAsText = new String(msgAsBytes); |
|
How well this works depends on the message ccsid, the platform's default charset, and whether the message contains multi-byte characters.
EKhalil wrote: |
So to get environment tree into a string I wrote this:
...
Which works just fine...but Im wondering if there is any better way to do this in JCN? |
Use the ESQL CREATE statement, (or similar Java MbElement.createElement methods), to associate a new element with a parser, so that the toBitstream() method can use the parser to serialize the element and its children. |
|
Back to top |
|
 |
marko.pitkanen |
Posted: Mon Nov 07, 2011 3:07 am Post subject: |
|
|
 Chevalier
Joined: 23 Jul 2008 Posts: 440 Location: Jamsa, Finland
|
Hi,
I think you could try to create branch for example to LocalEnvironment with XMLNSC domain. Copy your sub tree there and serialise that to bytes and convert it to string as you have done with root -object.
--
marko |
|
Back to top |
|
 |
EKhalil |
Posted: Mon Nov 07, 2011 10:48 am Post subject: |
|
|
Voyager
Joined: 29 Apr 2003 Posts: 99 Location: Boston, MA
|
Oh, ok...ty, will let you know how it goes... |
|
Back to top |
|
 |
EKhalil |
Posted: Thu Nov 10, 2011 10:12 pm Post subject: |
|
|
Voyager
Joined: 29 Apr 2003 Posts: 99 Location: Boston, MA
|
Followed your advice and used it on serializing exception tree as well:
String text =
//(String)assembly.getExceptionList().evaluateXPath("string(//ParserException/Text)");
(String)assembly.getExceptionList().evaluateXPath("string(//EvaException/Text)");
if (text.equals("")){
MbMessage exceptionTree = assembly.getExceptionList();
MbElement ExceptionTreeList = exceptionTree.getRootElement();
//
MbMessage localEnvironment = assembly.getLocalEnvironment();
MbElement xmlRoot =
localEnvironment.getRootElement().createElementAsLastChild(MbXMLNSC.PARSER_NAME);
MbElement xmlExceptionTreeList = xmlRoot.createElementAsLastChild(MbElement.TYPE_NAME,
"xmlExceptionTreeList", null);
xmlExceptionTreeList.copyElementTree(ExceptionTreeList);
byte [] msgAsBytes = localEnvironment.getRootElement().getLastChild().toBitstream(null,null,null,0,0,0);
String exAsText = new String(msgAsBytes); |
|
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
|
|
|
|