|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
how to copy localenv to a Mbelement in JCN |
« View previous topic :: View next topic » |
Author |
Message
|
new_to_wmb8 |
Posted: Thu Jul 30, 2015 9:58 am Post subject: how to copy localenv to a Mbelement in JCN |
|
|
 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 |
|
 |
mqjeff |
Posted: Thu Jul 30, 2015 10:06 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
|
Back to top |
|
 |
new_to_wmb8 |
Posted: Thu Jul 30, 2015 10:28 am Post subject: |
|
|
 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 |
|
 |
kimbert |
Posted: Fri Jul 31, 2015 3:03 am Post subject: |
|
|
 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.
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 |
|
 |
mqjeff |
Posted: Fri Jul 31, 2015 4:38 am Post subject: |
|
|
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..  |
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 |
|
 |
|
|
 |
|
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
|
|
|
|