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 » WebSphere Message Broker (ACE) Support » how to copy localenv to a Mbelement in JCN

Post new topic  Reply to topic
 how to copy localenv to a Mbelement in JCN « View previous topic :: View next topic » 
Author Message
new_to_wmb8
PostPosted: Thu Jul 30, 2015 9:58 am    Post subject: how to copy localenv to a Mbelement in JCN Reply with quote

Centurion

Joined: 28 May 2013
Posts: 127
Location: Hyderabad, India

Hi All,

I have to create a Cdata structure but rather than to use string concat , i want to to use xml parser in java code

below structure i have :

Code:

<XML>
 <![CDATA[
    <test>   
    <record>
      <name>Jack</name>
      <emp>98745</emp>
   </record>   
    </test>
    ]]>       
</XML>



so for this i am creating the xml parser and will asign the above value to string , like something below later in code

childMBE.createElementAsLastChild(MbXMLNSC.CDATA_VALUE, "XML", XMLRecord);

in below code i am trying to do is the above structure , i am able to do that. and want to save in the "XMLRecord"" .

Code:
MbElement refXMLRecord = localenv.createElementAsLastChild(MbXMLNSC.PARSER_NAME);
               refXMLRecord  = refXMLRecord.createElementAsLastChild(MbXMLNSC.FOLDER, "test", "");
               refXMLRecord  = refXMLRecord.createElementAsLastChild(MbXMLNSC.FOLDER, "record", "");
               refXMLRecord.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "name", name);   
               refXMLRecord.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "emp", emp);   


now how to i read the local env and map the same into the XMLRecord


Code:
refXMLRecord  = refXMLRecord.copy();         
MbElement XMLmsg ;
XMLmsg = localenv.getFirstElementByPath("./XMLNSC");
MbElement localenv_TreeCopy;   


but in outputroot under the XML tag nothing is coming ....pls anyone can help on this .[/code]
Back to top
View user's profile Send private message
mqjeff
PostPosted: Thu Jul 30, 2015 10:06 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

You need to make sure that the tree in local environment is created with a parser attached.

Then you need to call toBitstream.

http://www-01.ibm.com/support/knowledgecenter/api/content/nl/en-us/SSMKHH_9.0.0/com.ibm.etools.mft.plugin.doc/com/ibm/broker/plugin/MbElement.html

Then you need to make sure that the parser specific type on your CDATA element indicates that it's a CDATA element.
Back to top
View user's profile Send private message
new_to_wmb8
PostPosted: Thu Jul 30, 2015 10:28 am    Post subject: Reply with quote

Centurion

Joined: 28 May 2013
Posts: 127
Location: Hyderabad, India

Yeah parser is coming into Local env , now i need the same structure to be mapped to a different string that i use later, why need to call BitStream , below code will take care of Cdata right ?

Code:
childMBE.createElementAsLastChild(MbXMLNSC.CDATA_VALUE, "XML", XMLRecord);


can you pls give some code sample to copy the local env to a string something..
Back to top
View user's profile Send private message
kimbert
PostPosted: Fri Jul 31, 2015 3:03 am    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

Quote:
I have to create a Cdata structure but rather than to use string concat , i want to to use xml parser...
Good choice. String concat would be a very bad option.
Quote:
...in java code
Any reason why it has to be done in Java code? See below for some reasons why ESQL would almost certainly be a better choice.
Code:
childMBE.createElementAsLastChild(MbXMLNSC.CDATA_VALUE, "XML", XMLRecord);
I'm not convinced that using the name 'XML' for a syntax element is a great idea. It looks too much like the name of the old 'XML' domain. In any case, the name 'XML' does not say anything about what this subtree contains.

In order to make this work, you need to use the Java API really carefully.
- Ensure that the environment tree is owned by the XMLNSC parser. That means using the single-parameter constructor createElementAsLastChild(parserName)
- Set the parser-specific field type on the target element to XMLNSC.CDataField. You attempt is reasonable, and ought to work. But it doesn't. You need to explicitly set the field type using MbElement.setSpecificType(int type).
- Convert the message tree in the environment into a string using toBitstream and then cast the resulting byte array to a String ( and remember to supply the encoding explicitly!).

Alternatively, use a Compute node - the resulting code will be a lot simpler to maintain. Creating a field with a parser-specfic field type is easy in ESQL. ASBITSTREAM is the equivalent of the toBitstream call. This forum is full of examples.
_________________
Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Fri Jul 31, 2015 4:38 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

new_to_wmb8 wrote:
can you pls give some code sample to copy the local env to a string something..




mqjeff wrote:

Then you need to call toBitstream.

http://www-01.ibm.com/support/knowledgecenter/api/content/nl/en-us/SSMKHH_9.0.0/com.ibm.etools.mft.plugin.doc/com/ibm/broker/plugin/MbElement.html


kimbert wrote:
- Convert the message tree in the environment into a string using toBitstream and then cast the resulting byte array to a String ( and remember to supply the encoding explicitly!).
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 » WebSphere Message Broker (ACE) Support » how to copy localenv to a Mbelement in JCN
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.