Wednesday, 13 September 2023

Handling BLOB message(xml data as blob) in Esql



                                 Parsing XML data from a blob message




/** input of this sample is a XML message 
                 ** <XmlCollection>
                 **<Collection>3c546573743e48656c6c6f20507269796573683c2f546573743e</Collection>
                 **</XmlCollection>

Collection is a XML data in hexadecimal (BLOB) representation
Create an element of type parser

**/

CREATE LASTCHILD OF OutputRoot DOMAIN 'XMLNSC' NAME 'XMLNSC';
-- Create the root tag element of your output XML
CREATE LASTCHILD OF OutputRoot.XMLNSC NAME 'RootTag';

IF EXISTS(InputRoot.BLOB[]) THEN
------<Test>Hello Priyesh</Test>---
CREATE LASTCHILD OF OutputRoot.XMLNSC.RootTag.RecSec PARSE(CAST(InputRoot.BLOB.BLOB AS BLOB) OPTIONS FolderBitStream CCSID 1208 FORMAT 'XMLNSC');

ELSE



DECLARE ptrCollection REFERENCE TO InputRoot.XMLNSC.XmlCollection.Collection;
WHILE LASTMOVE(ptrCollection) DO
--Parse the BLOB into XML using the PARSE function
CREATE LASTCHILD OF OutputRoot.XMLNSC.RootTag.RecSec PARSE(CAST(ptrCollection AS BLOB) OPTIONS FolderBitStream CCSID 1208 FORMAT 'XMLNSC');
MOVE ptrCollection NEXTSIBLING;
END WHILE;

END IF;




 Parsing XML data into blob message



/***
****  Sample input to convert into BLOB
--------------------------
<Orders>
<Order>
<OrderDetails>
<OrderID>1234</OrderID>
<NumOfItems>2</NumOfItems>
<TotalAmount>3000</TotalAmount>
<OrderDate>07/13/2017</OrderDate>
</OrderDetails>
</Order>
<Order>
<OrderDetails>
<OrderID>1235</OrderID>
<NumOfItems>4</NumOfItems>
<TotalAmount>6000</TotalAmount>
<OrderDate>07/13/2017</OrderDate>
</OrderDetails>
</Order>
</Orders>
------------------------
****/

--- creating blob message domain

CREATE LASTCHILD OF OutputRoot DOMAIN 'BLOB' NAME 'BLOB';

--creating blob root for the message

CREATE LASTCHILD OF OutputRoot.BLOB NAME 'BLOB';

-- creating a reference to the blob message root.

DECLARE refBlob REFERENCE TO OutputRoot.BLOB.BLOB;

-- assigning message data by converting it into blob using ASBITSTREAM function-

SET refBlob = ASBITSTREAM(InputRoot.XMLNSC.*[>] OPTIONS FolderBitStream CCSID 1208);


--- Creating Environment variable to get the xml data back for verification whether previous conversion was successful
----and contains data properly.

CREATE LASTCHILD OF Environment DOMAIN 'XMLNSC' NAME 'XMLNSC';

CREATE LASTCHILD OF Environment.XMLNSC  PARSE(CAST(OutputRoot.BLOB.BLOB AS BLOB) OPTIONS FolderBitStream CCSID 1208 FORMAT 'XMLNSC');



Output :










No comments:

Post a Comment

Sending file as multi-part MIME over http in ACE - esql

  How to send a file over http as a multipart mime? Below are the steps to do that - 1. Make sure you have the data encryption in place for ...