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 IndexWebSphere Message Broker SupportConvert XML to String in ESQL

Post new topicReply to topic
Convert XML to String in ESQL View previous topic :: View next topic
Author Message
abinaya
PostPosted: Tue Jan 23, 2018 2:12 am Post subject: Convert XML to String in ESQL Reply with quote

Novice

Joined: 20 Jun 2017
Posts: 17

Hi All ,

I know this is a topic which has lot of reference posts in MQSERIES , But I am raising a new thread as I already tried with all options. Apologies .

I have a XML wrapped in a CDATA (XML is quite huge) , I want the XML to be converted as String.

I referred this link
https://www.ibm.com/developerworks/community/forums/html/topic?id=f926de67-09e2-47cb-ab06-c83f87630f9f

and http://www.mqseries.net/phpBB/viewtopic.php?p=273444&sid=fd1c9fb82ae36eea1bb8a603cd6600e5

but I cannot go through the XML field by field as the XML is huge. Is there any other way where the whole xml can be converted to character with ASBITSTREAM . Thanks in advance .
Back to top
View user's profile Send private message
souciance
PostPosted: Tue Jan 23, 2018 4:36 am Post subject: Reply with quote

Disciple

Joined: 29 Jun 2010
Posts: 158

What code have you tried?

Why don't you convert it to BLOB? What errors are you getting?
Back to top
View user's profile Send private message
abinaya
PostPosted: Tue Jan 23, 2018 4:48 am Post subject: Reply with quote

Novice

Joined: 20 Jun 2017
Posts: 17

DECLARE inMessage BLOB;
SET inMessage = ASBITSTREAM(InputRoot.XMLNSC OPTIONS FolderBitStream CCSID 1208);
DECLARE cMessage CHARACTER CAST(inMessage AS CHARACTER ENCODING 546);
SET OutputRoot.BLOB.BLOB = cMessage;

This is the code I am trying , and In trace the error I see is

A value of SQL datatype ''CHARACTER'' encountered when datatype ''BLOB'' expected.
The value of SQL datatype 'CHARACTER' was encountered, but a value of SQL datatype 'BLOB' was expected.
Back to top
View user's profile Send private message
timber
PostPosted: Tue Jan 23, 2018 4:51 am Post subject: Reply with quote

Sentinel

Joined: 25 Aug 2015
Posts: 855

Quote:
I have a XML wrapped in a CDATA (XML is quite huge) , I want the XML to be converted as String.
The contents of the CDATA section is already a string. That's what the error message is trying to tell you.
Back to top
View user's profile Send private message
abinaya
PostPosted: Tue Jan 23, 2018 8:03 am Post subject: Reply with quote

Novice

Joined: 20 Jun 2017
Posts: 17

I tried the logic without CDATA, even that is resulting in same error . To be more clear ., I will be having an xml containing exception information and in a xml tag called original input the actual input xml is stored inside CDATA wrapper . I need to take that xml data and convert to a string . As a initial test I tried a simple xml also without CDATA but it results in the error mentioned
Back to top
View user's profile Send private message
Vitor
PostPosted: Tue Jan 23, 2018 8:20 am Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 25250
Location: Ohio, USA

abinaya wrote:
I tried the logic without CDATA, even that is resulting in same error . To be more clear ., I will be having an xml containing exception information and in a xml tag called original input the actual input xml is stored inside CDATA wrapper . I need to take that xml data and convert to a string . As a initial test I tried a simple xml also without CDATA but it results in the error mentioned


Ok, things are very mixed up in that statement. As my worthy associate says, the CDATA is already a character string. So you don't need ASBITSTREAM or any other conversion.

What's wrong with:

Code:
SET OutputRoot.BLOB.BLOB = CAST(InputRoot.XMLNSC.whatever.whatever.theXMLyouwant AS BLOB);

_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
abinaya
PostPosted: Tue Jan 23, 2018 10:04 pm Post subject: Reply with quote

Novice

Joined: 20 Jun 2017
Posts: 17

This is the Input XML
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<event><applicationData><![CDATA[<complexContent><name><family>family0</family><family1>family01</family1></name></complexContent>]]></applicationData></event>

I want the output as family0 family01

Meaning, I need only the values of the huge XML content inside CDATA . I hope I am clear now .

SET OutputRoot.BLOB.BLOB = CAST(InputRoot.XMLNSC.event.(XMLNSC.CDataField)applicationData AS BLOB CCSID InputRoot.Properties.CodedCharSetId); gives me the whole XML as output .
Back to top
View user's profile Send private message
abhi_thri
PostPosted: Wed Jan 24, 2018 12:20 am Post subject: Reply with quote

Master

Joined: 17 Jul 2017
Posts: 217
Location: UK

Hi there... If you want to extract the values from the xml tree you need to write a function/procedure to do so (eg:- you can use anonymous references and move/lastmove/while loop etc to drill through the tree and copy/build the value string).

Is this a real requirement as such or you are doing some POC? because once you extract the values how do you interpret it later in downstream systems as it won't have any context...eg:- how does a system know say a value 'xxx' came from name/family1
Back to top
View user's profile Send private message
abinaya
PostPosted: Wed Jan 24, 2018 1:47 am Post subject: Reply with quote

Novice

Joined: 20 Jun 2017
Posts: 17

I want to pass the Text extracted to a flow with MQ Input to parse as IDOC . Is there no other way other than traversing the whole xml to extract values alone ?
Back to top
View user's profile Send private message
Vitor
PostPosted: Wed Jan 24, 2018 5:52 am Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 25250
Location: Ohio, USA

abinaya wrote:
Is there no other way other than traversing the whole xml to extract values alone ?


No.

If you want to extract string values from an XML structure (which is different from your original question, where you implied you wanted the whole XML as a string) then you need to parse the XML to identify which parts of the "string" are tags and which parts are values.

In the same way you'd need to with any XML document, which is always presented to the consuming application as a character string if you think about it.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
timber
PostPosted: Wed Jan 24, 2018 8:51 am Post subject: Reply with quote

Sentinel

Joined: 25 Aug 2015
Posts: 855

Quote:
I want to pass the Text extracted to a flow with MQ Input to parse as IDOC
You are describing your requirements in a very confusing way.
Please explain
- what your message flow needs to do, from a *business* perspective
- the input data format (XML, I think)
- the output data format ( IDOC? Really?)

If you actually want to output an IDOC then you should not be writing ESQL to do that. You probably need either a SAP adaptor or else you need to construct a DFDL model which will write the message tree in the correct format.
But all of that is based on my assumption that you want to output a large, complex IDOC.
Back to top
View user's profile Send private message
abinaya
PostPosted: Tue Jan 30, 2018 1:36 am Post subject: Reply with quote

Novice

Joined: 20 Jun 2017
Posts: 17

My intention was below ,

Flow 1 ( Generic IDOC Router) -> Flow 2 (With MQ Input Node)

Flow 1 receives IDOC and passes to Flow 2 and Flow 2 parses with DataObject Domain and with Physical format as SAP ALE IDOC . This process works very fine.

The reason behind my post was : If Flow 2 ends in some error , Instead of triggering IDOC from SAP we want to replay the message from Flow 2 itself which has MQ Input Node . Flow 2 expects a character stream of data , not IDOC XML . But when I store the input as part of error processing I get only XML (which is character stream Parsed against IDOC Schema) .

After few trials, Now we left the idea of triggering Flow 2 separately ,so closing the post. Thanks for response.
Back to top
View user's profile Send private message
abhi_thri
PostPosted: Tue Jan 30, 2018 1:53 am Post subject: Reply with quote

Master

Joined: 17 Jul 2017
Posts: 217
Location: UK

Hi...it may be worth looking at the error handling logic as ideally it should sent the unmodified input message (flat IDoc format) to the backout queue and not the XML-IDoc. We've a similar setup where a set of flows are dedicated to pull IDocs from SAP and route to downstream flows. If an error occurs in the downstream flow it successfully logs the message to backout queue in its original format so that it can be replayed if required so.

So have a look at the error logic to see whether it is doing anything to modify the message, if all the errors in the flow are handled via the catch terminal at the MQInput node and the catch logic then rethrows the error (to force transaction rollback) then you should see the original msg ending up at the backout queue without any modification.
Back to top
View user's profile Send private message
Display posts from previous:
Post new topicReply to topic Page 1 of 1

MQSeries.net Forum IndexWebSphere Message Broker SupportConvert XML to String in ESQL
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.