Author |
Message
|
nelson |
Posted: Thu May 07, 2015 10:41 am Post subject: Build DFDL tree from BLOB |
|
|
 Partisan
Joined: 02 Oct 2012 Posts: 313
|
Hi All,
I'm trying yo save the DFDL tree and in the future build it again. This looks silly (bacause I'm not storing the DFDL tree nowhere), but should work I think and demonstrates my issue:
Code: |
CREATE LASTCHILD OF OutputRoot DOMAIN('DFDL')
PARSE(ASBITSTREAM(InputRoot.DFDL OPTIONS RootBitStream) ENCODING InputRoot.MQMD.Encoding CCSID InputRoot.MQMD.CodedCharSetId SET '' TYPE '{}:MYMSG' OPTIONS RootBitStream); |
The tree is never created properly... I've tried a lot of combinations and options, but it always fails:
Code: |
DFDL
MYMSG
CHARACTER:DFDL parsing errors have occurred |
I need some help on how to store the DFDL tree and then how to send it to the CREATE statement...
Any help is very appreciated.
Thanks a lot for your help. |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu May 07, 2015 11:10 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Consider doing it the same way you would parse an XMLNSC tree...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
maurito |
Posted: Fri May 08, 2015 12:08 am Post subject: Re: Build DFDL tree from BLOB |
|
|
Partisan
Joined: 17 Apr 2014 Posts: 358
|
Your inputroot is already parsed ( as DFDL ), so you only need to save as bitstream, for example:
Code: |
SET envRef.Message = ASBITSTREAM(InputRoot.DFDL.*:* CCSID propRef.CodedCharSetId ENCODING propRef.Encoding); |
where propRef is a reference to the input Properties folder
you will need to parse when restoring to DFDL
or you can save the already parsed message by creating a folder with the DFDL parser associated to it, and then copy directly from input root to that folder.
to restore your as bistream saved message:
Code: |
CREATE LASTCHILD OF OutputRoot DOMAIN('DFDL') PARSE(savedmsg,0,0,'','{}:yourmessage','',RootBitStream); |
Note that in the ASBITSTREAM you need to specify ccsid and encoding so that it knows how to deal with endianess, etc., and probably that is the cause of your error. |
|
Back to top |
|
 |
Simbu |
Posted: Fri May 08, 2015 2:05 am Post subject: |
|
|
 Master
Joined: 17 Jun 2011 Posts: 289 Location: Tamil Nadu, India
|
|
Back to top |
|
 |
nelson |
Posted: Fri May 08, 2015 4:42 am Post subject: |
|
|
 Partisan
Joined: 02 Oct 2012 Posts: 313
|
Thank to all for your suggestions. It finally worked this way:
Code: |
DECLARE inCCSID INT InputProperties.CodedCharSetId;
DECLARE inEncoding INT InputProperties.Encoding;
DECLARE inBitStream BLOB ASBITSTREAM(InputRoot.DFDL, inEncoding, inCCSID);
DECLARE inBitStreamStr CHARACTER SUBSTRING(CAST(inBitStream AS CHARACTER) FROM 3 FOR LENGTH(inBitStreamStr) - 3);
...
...
...
DECLARE newBlob BLOB CAST(inBitStreamStr AS BLOB);
CREATE LASTCHILD OF OutputRoot DOMAIN('DFDL') PARSE(newBlob ENCODING InputRoot.MQMD.Encoding CCSID InputRoot.MQMD.CodedCharSetId SET '' TYPE '{}:MyMsg'); |
The issue was how to store the BLOB as string in memory and then restore it to BLOB again.
Regards. |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri May 08, 2015 5:18 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
nelson wrote: |
Code: |
DECLARE inBitStream BLOB ASBITSTREAM(InputRoot.DFDL, inEncoding, inCCSID);
DECLARE inBitStreamStr CHARACTER SUBSTRING(CAST(inBitStream AS CHARACTER) FROM 3 FOR LENGTH(inBitStreamStr) - 3);
|
|
Out of curiosity, why switch to Character and why skip the first 3 bytes?  _________________ MQ & Broker admin |
|
Back to top |
|
 |
nelson |
Posted: Fri May 08, 2015 5:38 am Post subject: |
|
|
 Partisan
Joined: 02 Oct 2012 Posts: 313
|
fjb_saper wrote: |
nelson wrote: |
Code: |
DECLARE inBitStream BLOB ASBITSTREAM(InputRoot.DFDL, inEncoding, inCCSID);
DECLARE inBitStreamStr CHARACTER SUBSTRING(CAST(inBitStream AS CHARACTER) FROM 3 FOR LENGTH(inBitStreamStr) - 3);
|
|
Out of curiosity, why switch to Character and why skip the first 3 bytes?  |
When I cast the BLOB to CHARACTER " X' " is concatenated to the start of the string and " ' " at the end, so when you try to cast this string again to BLOB it says that the string is not valid.... Is there a better way to do this? |
|
Back to top |
|
 |
mqjeff |
Posted: Fri May 08, 2015 5:46 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Why do you need to cast it to character? |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri May 08, 2015 5:48 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
nelson wrote: |
When I cast the BLOB to CHARACTER " X' " is concatenated to the start of the string and " ' " at the end, so when you try to cast this string again to BLOB it says that the string is not valid.... Is there a better way to do this? |
And you expected anything different? When you cast a BLOB to CHARACTER without specifying any CCSID, what you get is a hex representation of the BLOB. (Default).
I would have expected something like
Code: |
DECLARE inBitStreamStr CHARACTER CAST(inBitStream AS CHARACTER inEncoding, inCCSID); |
if what you wanted was the String representation of the bitstream... assuming of course that the bitstream only contains characters...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
nelson |
Posted: Fri May 08, 2015 6:10 am Post subject: |
|
|
 Partisan
Joined: 02 Oct 2012 Posts: 313
|
fjb_saper wrote: |
nelson wrote: |
When I cast the BLOB to CHARACTER " X' " is concatenated to the start of the string and " ' " at the end, so when you try to cast this string again to BLOB it says that the string is not valid.... Is there a better way to do this? |
And you expected anything different? When you cast a BLOB to CHARACTER without specifying any CCSID, what you get is a hex representation of the BLOB. (Default).
I would have expected something like
Code: |
DECLARE inBitStreamStr CHARACTER CAST(inBitStream AS CHARACTER inEncoding, inCCSID); |
if what you wanted was the String representation of the bitstream... assuming of course that the bitstream only contains characters...  |
In fact, your statement generates something like:
The string that I need is:
Since
Code: |
CAST(inBitStreamStr AS BLOB ...) |
says inBitStreamStr is invalid, it works fine with the second string. |
|
Back to top |
|
 |
mqjeff |
Posted: Fri May 08, 2015 6:40 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
nelson wrote: |
The string that I need is:
|
Why do you need it as a string? |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri May 08, 2015 6:46 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Looks to me like you are doing some unholy comparison here:
byte[] to hex String => look for some String value...
That really should have been in ESQL check if BLOB a is in BLOB b... _________________ MQ & Broker admin |
|
Back to top |
|
 |
nelson |
Posted: Fri May 08, 2015 7:10 am Post subject: |
|
|
 Partisan
Joined: 02 Oct 2012 Posts: 313
|
mqjeff wrote: |
nelson wrote: |
The string that I need is:
|
Why do you need it as a string? |
I'm storing this value in a Hashtable in Java... |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri May 08, 2015 7:43 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
nelson wrote: |
mqjeff wrote: |
nelson wrote: |
The string that I need is:
|
Why do you need it as a string? |
I'm storing this value in a Hashtable in Java... |
?? ?? ??
As a value or a key? _________________ MQ & Broker admin |
|
Back to top |
|
 |
nelson |
Posted: Fri May 08, 2015 7:44 am Post subject: |
|
|
 Partisan
Joined: 02 Oct 2012 Posts: 313
|
fjb_saper wrote: |
nelson wrote: |
mqjeff wrote: |
nelson wrote: |
The string that I need is:
|
Why do you need it as a string? |
I'm storing this value in a Hashtable in Java... |
?? ?? ??
As a value or a key? |
As a value |
|
Back to top |
|
 |
|