Author |
Message
|
anurag.munjal |
Posted: Wed Sep 26, 2012 11:04 am Post subject: CDATA to MQ |
|
|
 Voyager
Joined: 08 Apr 2012 Posts: 97
|
Hi MB Champs!
I have a XML request message as below:
<body>
<payload>
<![CDATA[TheBodyOfCdataWhichIsToBePutOnTheQueue]]>
</payload>
</body>
I want to put the content of the CDATA i.e. 'TheBodyOfCdataWhichIsToBePutOnTheQueue' as it is without any transformation onto a MQ.
I have tried a lot of approaches but am missing the point!
Any suggestion?
Anurag Munjal
New delhi
+91 - 9990602099 |
|
Back to top |
|
 |
lancelotlinc |
Posted: Wed Sep 26, 2012 11:14 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
|
Back to top |
|
 |
Vitor |
Posted: Wed Sep 26, 2012 12:25 pm Post subject: Re: CDATA to MQ |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
anurag.munjal wrote: |
I have tried a lot of approaches but am missing the point! |
Such as? There's no point us suggesting something which has already proved to be ineffective for you. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
NealM |
Posted: Wed Sep 26, 2012 1:59 pm Post subject: |
|
|
 Master
Joined: 22 Feb 2011 Posts: 230 Location: NC or Utah (depends)
|
It can be hard for a newbie to understand that there is no "text" or "string" parser in the Broker. Any incoming/outgoing message of that type (that doesn't have a message set defined for it) needs to be treated as a BLOB. I suggest you spend a few minutes in the InfoCenter (see lancelot's link) reading up on BLOB. Especially note the examples in "Manipulating messages in the BLOB domain".
Regarding retrieving data from your XML, you don't need to worry about the CDATA tag, the Broker handles that. You just want to grab the contents of Root.XMLNS.Body.Payload in your ESQL's SET =.
If on the other hand you wanted to create an XML CDATA section, you then would need to read up on how to specify for your particular parser, XML/XMLNS/XMLNSC. |
|
Back to top |
|
 |
kimbert |
Posted: Wed Sep 26, 2012 2:22 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
That's good advice from NealM.
Quote: |
If on the other hand you wanted to create an XML CDATA section, you then would need to read up on how to specify for your particular parser, XML/XMLNS/XMLNSC. |
That makes it sound as if there are three equally good options. In fact, XMLNSC is the best choice for a new message flow unless there are good reasons why not *and* you can articulate exactly what those reasons are. I think NealM was allowing for the possibility that you are working on a set of old flows that all use XMLNS.
Anyway, to avoid confusion, the ESQL that the OP needs is
Code: |
DECLARE myCDATA CHARACTER;
SET myCData = InputRoot.XMLNSC.body.payload;
SET OutputRoot.BLOB.BLOB = CAST myCData as CHARACTER ENCODING <insert the required CCSID here>; |
If you want to, you can collapse that into one line once you understand what's going on. |
|
Back to top |
|
 |
anurag.munjal |
Posted: Wed Sep 26, 2012 8:43 pm Post subject: |
|
|
 Voyager
Joined: 08 Apr 2012 Posts: 97
|
Hi lancelotlinc,
So true! am a newbie... plus my mentor is to busy to help me out! but yes, i will go through the link to gain better grip on the topic! Thanks
Hi Vitor,
The approaches i tried are not to point am sure. still ill tell u
1. i tried to put the cdata section content onto a tag in xml. i could do that all without any aprsing, but i was getting the '< |
anurag.munjal |
Posted: Wed Sep 26, 2012 8:57 pm Post subject: |
|
|
 Voyager
Joined: 08 Apr 2012 Posts: 97
|
Hi NealM,
So when u say that grab the contents of Root.XMLNS.Body.Payload in your ESQL's SET =, what shall i set it into? a character type variable? will this variable be able to store CDATA content?? what convertion do i need to do?? cast as character?
the data in the CDATA section is BLOB, right? |
|
Back to top |
|
 |
anurag.munjal |
Posted: Wed Sep 26, 2012 9:09 pm Post subject: |
|
|
 Voyager
Joined: 08 Apr 2012 Posts: 97
|
Hi Jedi Knight,
Thanks for the code snippet.
DECLARE myCDATA CHARACTER;
SET myCData = InputRoot.XMLNSC.body.payload;
SET OutputRoot.BLOB.BLOB = CAST myCData as CHARACTER ENCODING <insert the required CCSID here>;
My doubts are:
1. when u say, SET myCData = InputRoot.XMLNSC.body.payload; will the contents of cdata section flow into charecter type variable as it is? without the
'< |
anurag.munjal |
Posted: Wed Sep 26, 2012 9:11 pm Post subject: |
|
|
 Voyager
Joined: 08 Apr 2012 Posts: 97
|
Guys, i read it somewhere....
"extract the CData section as a BLOB". [/code] |
|
Back to top |
|
 |
vikas.bhu |
Posted: Wed Sep 26, 2012 9:14 pm Post subject: |
|
|
Disciple
Joined: 17 May 2009 Posts: 159
|
Cast the message in character..find the start position and end position of the message you want to put forward. and finally use substring function.
Hope it helps |
|
Back to top |
|
 |
rekarm01 |
Posted: Wed Sep 26, 2012 11:18 pm Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 1415
|
kimbert wrote: |
Anyway, to avoid confusion, the ESQL that the OP needs is
Code: |
DECLARE myCDATA CHARACTER;
SET myCData = InputRoot.XMLNSC.body.payload;
SET OutputRoot.BLOB.BLOB = CAST myCData as CHARACTER ENCODING <insert the required CCSID here>; |
|
The last line needs a few minor adjustments:
Code: |
DECLARE myCDATA CHARACTER;
SET myCData = InputRoot.XMLNSC.body.payload;
SET OutputRoot.BLOB.BLOB = CAST(myCData as BLOB CCSID <insert the required CCSID here>); |
This converts the CData contents from CHARACTER to BLOB using the given ccsid, and writes the resulting BLOB to the output message. |
|
Back to top |
|
 |
anurag.munjal |
Posted: Thu Sep 27, 2012 1:02 am Post subject: rekarm01 - THANKSSSSSSSSS |
|
|
 Voyager
Joined: 08 Apr 2012 Posts: 97
|
Hi rekarm01,
Ur suggestion is on target!
ITS WORKING!
I am so happy to be a part of this awsome community!! Thanks a lot guys!!
 |
|
Back to top |
|
 |
kimbert |
Posted: Thu Sep 27, 2012 3:00 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Thanks rekarm01. Accurate as usual!
@vikas.bhu: Please don't offer bad advice on this forum. |
|
Back to top |
|
 |
NealM |
Posted: Thu Sep 27, 2012 4:54 am Post subject: |
|
|
 Master
Joined: 22 Feb 2011 Posts: 230 Location: NC or Utah (depends)
|
One other thing, Anurag:
All data in an XML doc is always text, all elements/attributes, all the time. Valid characters for the codepage that is specified for the XML document. The data in a CDATA section is no exception. All it does is preserve whitespace (multiple/leading/trailing blanks, etc) in the data, whereas normal XML processing may remove some or all of them. So one uses CDATA to preserve a string exactly. If one wanted to send a BLOB as an element in an XML doc, what one does is send a pseudo-hex representation of a BLOB. Still character data. So a two byte piece of data would be sent as a 4 byte pseudo-hex (whether or not to include the "X'..'" surrounding the pseudo-hex is users choice). That requires a little more work in correctly CASTing at both ends. One would do that if you were trying to include non-text data in the XML, such as say packed decimal data, or data from a different CCSID, which would otherwise blow up in an XML processor/parser. That is not your case. |
|
Back to top |
|
 |
anurag.munjal |
Posted: Wed Oct 03, 2012 5:57 am Post subject: |
|
|
 Voyager
Joined: 08 Apr 2012 Posts: 97
|
Thanks Neal!
one quick query:
Can you help me differentiate between these three statements?
SET OutputRoot.XMLNSC.Envelope.Body.(XMLNSC.CDataField)payload = some_msg;
SET OutputRoot.XML.Envelope.Body.(XML.CDataSection)payload = some_msg;
SET OutputRoot.XMLNSC.Envelope.Body.(XML.CDataSection)payload = some_msg; |
|
Back to top |
|
 |
|