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 Index » General Discussion » ESQL: Parsing a Character (XML string)

Post new topic  Reply to topic
 ESQL: Parsing a Character (XML string) « View previous topic :: View next topic » 
Author Message
emqueuer
PostPosted: Thu Jun 28, 2007 3:36 am    Post subject: ESQL: Parsing a Character (XML string) Reply with quote

Novice

Joined: 21 Jun 2007
Posts: 24

Hello,

I have an XML string which is stored as a shared Character variable and I require it to be be parsed/structured so that I may loop around it in an ESQL function, in order to retrieve certain field values. I already have a separate message in the InputRoot which must not be confused with this string.

Is there a way I can cast the string in question so that it can be looped as if it were the InputRoot, albeit for read-only reasons.

Many thanks

Daniel
Back to top
View user's profile Send private message
special_agent_Queue
PostPosted: Thu Jun 28, 2007 4:52 am    Post subject: Reply with quote

Centurion

Joined: 27 Jul 2006
Posts: 102

check out the CREATE...PARSE statement.
Back to top
View user's profile Send private message
emqueuer
PostPosted: Fri Jun 29, 2007 1:48 am    Post subject: Reply with quote

Novice

Joined: 21 Jun 2007
Posts: 24

Hello,

I'm trying to implement the CREATE...PARSE function but, surprise surprise, am hittting obstacles along the way.

Can anyone help please?

------------------------------------------------------------------------
In a compute node I'm trying to parse some XML from a string and put into the LE as InputRoot.LocalEnvironment.MyData as follows:
-----------------------------------------------------------------
DECLARE CacheQueueBlob SHARED BLOB;

CREATE COMPUTE MODULE CreateMapping_Compute
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN

CALL CopyEntireMessage();

CREATE LASTCHILD OF InputRoot.LocalEnvironment.MyData
VALUE '<SuperMods><MapData To="INM304_2006-07"><From>INM305_2006-07</From><From>INM306_2006-07</From></MapData><MapData To="INM332_2006-07"><From>IN2012_2006-07</From></MapData></SuperMods>';

SET CacheQueueBlob = ASBITSTREAM(InputRoot.LocalEnvironment.MyData,
InputProperties.Encoding,
InputProperties.CodedCharSetId);

CREATE LASTCHILD OF InputRoot.LocalEnvironment.MyData DOMAIN('XMLNS') PARSE(CacheQueueBlob,
InputProperties.Encoding,
InputProperties.CodedCharSetId);

RETURN TRUE;
END;
-----------------------------------------------------------------

...and then in another compute further down the flow I am trying to loop the XML as follows:

-----------------------------------------------------------------

CREATE PROCEDURE FindSupermoduleMapping(IN CurrentModuleID CHARACTER) BEGIN

DECLARE Y REFERENCE TO InputRoot.LocalEnvironment.MyData.SuperMods;

DECLARE I INTEGER 1;
DECLARE J INTEGER CARDINALITY(Y.*[]);

SET OutputRoot.XMLNS.Test.CardinalityOfMappings = J;

WHILE I <= J DO

SET OutputRoot.XMLNS.Test.InsideFirstLoop = 'yes';

--nested loop of MapData
DECLARE P INTEGER 1;
DECLARE Q INTEGER CARDINALITY(Y.MapData.*[]);
WHILE P <= Q DO
SET OutputRoot.XMLNS.Test.Yes = 'inside nested loop';
IF Y.MapData[I].From[P] = CurrentModuleID THEN
SET OutputRoot.XMLNS.SuperModules.MapTo = Y.MapData.(XMLNSC.Attribute)To;
END IF;

-- SET OutputRoot.XMLNS.SuperModules.NoOfCh[P] = 'nb';
SET P = P + 1;
END WHILE;

SET I = I + 1;
END WHILE;
END;
-----------------------------------------------------------------

However when deployed and run it is getting as far as 'SET OutputRoot.XMLNS.Test.InsideFirstLoop = 'yes';' but no further.

Also, J is always 3 (SET OutputRoot.XMLNS.Test.CardinalityOfMappings = J) irrespective of how many children are hardcoded in the parsed xml.


I am very confused and at least hope someone understands the query I'm trying to put across - even better if anyone has any suggestions. Would be greatly appreciated.

Thanks
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Fri Jun 29, 2007 3:06 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

You have VIOLATED rule #1

InputRoot is IMMUTABLE => IT CANNOT BE CHANGED:
so why are you coding this?
emqueuer wrote:
CREATE LASTCHILD OF InputRoot.LocalEnvironment.MyData
VALUE '<SuperMods><MapData To="INM304_2006-07"><From>INM305_2006-07</From><From>INM306_2006-07</From></MapData><MapData To="INM332_2006-07"><From>IN2012_2006-07</From></MapData></SuperMods>';


Try putting it to Environment.temp instead.... and you might need to specify a domain first... Use the search button and read the manuals!

You have been told to use CREATE PARSE in order to get the tree... but your stuff won't work => Why are you serializing (ASBITSTREAM) something that is already serialized. Just cast your value (string) to BLOB, then use CREATE PARSE.

What you used is essentially serialize a tree part into a bitstream and parse it again...whereas what you have is not a tree but a bitstream defined as a char....

Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
emqueuer
PostPosted: Fri Jun 29, 2007 5:01 am    Post subject: Reply with quote

Novice

Joined: 21 Jun 2007
Posts: 24

OK. I'm following your advice. i.e.:
------------------------------------------------------------------

DECLARE xmlString CHARACTER '<SuperMods><MapData><From>INM305_2006-07</From><From>INM306_2006-07</From></MapData></SuperMods>';

SET CacheQueueBlob = CAST (xmlString AS BLOB);

CREATE LASTCHILD OF Environment.MyData DOMAIN('XMLNS') PARSE(CacheQueueBlob,
InputProperties.Encoding,
InputProperties.CodedCharSetId);

------------------------------------------------------------------
But am getting this error.It doesn't like the string I'm casting into a BLOB:
------------------------------------------------------------------

DECLARE xmlString CHARACTER '<SuperMods><MapData><From>INM305_2006-07</From><From>INM306_2006-07</From></MapData></SuperMods>';
-- CREATE LASTCHILD OF Environment.MyData
-- VALUE '<SuperMods><MapData To="INM304_2006-07"><From>INM305_2006-07</From><From>INM306_2006-07</From></MapData><MapData To="INM332_2006-07"><From>IN2012_2006-07</From></MapData></SuperMods>';

SET CacheQueueBlob = CAST (xmlString AS BLOB);

-- SET CacheQueueBlob = ASBITSTREAM(InputRoot.LocalEnvironment.MyData,
-- InputProperties.Encoding,
-- InputProperties.CodedCharSetId);

CREATE LASTCHILD OF Environment.MyData DOMAIN('XMLNS') PARSE(CacheQueueBlob,
InputProperties.Encoding,
InputProperties.CodedCharSetId);
-----------------------------------------------------------

Description:
( SB3256_BRKR.default ) Error casting character string ''<SuperMods><MapData><From>INM305_2006-07</From><From>INM306_2006-07</From></MapData></SuperMods>'' to a byte string.

An attempt was made to cast the character string ''<SuperMods><MapData><From>INM305_2006-07</From><From>INM306_2006-07</From></MapData></SuperMods>'' to a byte string, but the string was of the wrong format. There must be an even number of hexadecimal digits (0-9, a-f, A-F).
Back to top
View user's profile Send private message
emqueuer
PostPosted: Fri Jun 29, 2007 5:03 am    Post subject: Reply with quote

Novice

Joined: 21 Jun 2007
Posts: 24

OK. I'm following your advice. i.e.:
------------------------------------------------------------------

DECLARE xmlString CHARACTER '<SuperMods><MapData><From>INM305_2006-07</From><From>INM306_2006-07</From></MapData></SuperMods>';

SET CacheQueueBlob = CAST (xmlString AS BLOB);

CREATE LASTCHILD OF Environment.MyData DOMAIN('XMLNS') PARSE(CacheQueueBlob,
InputProperties.Encoding,
InputProperties.CodedCharSetId);

------------------------------------------------------------------
But am getting the following error.It doesn't like the string I'm casting into a BLOB. Any suggestions please?
------------------------------------------------------------------

DECLARE xmlString CHARACTER '<SuperMods><MapData><From>INM305_2006-07</From><From>INM306_2006-07</From></MapData></SuperMods>';
-- CREATE LASTCHILD OF Environment.MyData
-- VALUE '<SuperMods><MapData To="INM304_2006-07"><From>INM305_2006-07</From><From>INM306_2006-07</From></MapData><MapData To="INM332_2006-07"><From>IN2012_2006-07</From></MapData></SuperMods>';

SET CacheQueueBlob = CAST (xmlString AS BLOB);

-- SET CacheQueueBlob = ASBITSTREAM(InputRoot.LocalEnvironment.MyData,
-- InputProperties.Encoding,
-- InputProperties.CodedCharSetId);

CREATE LASTCHILD OF Environment.MyData DOMAIN('XMLNS') PARSE(CacheQueueBlob,
InputProperties.Encoding,
InputProperties.CodedCharSetId);
-----------------------------------------------------------

Description:
( SB3256_BRKR.default ) Error casting character string ''<SuperMods><MapData><From>INM305_2006-07</From><From>INM306_2006-07</From></MapData></SuperMods>'' to a byte string.

An attempt was made to cast the character string ''<SuperMods><MapData><From>INM305_2006-07</From><From>INM306_2006-07</From></MapData></SuperMods>'' to a byte string, but the string was of the wrong format. There must be an even number of hexadecimal digits (0-9, a-f, A-F).
Back to top
View user's profile Send private message
emqueuer
PostPosted: Fri Jun 29, 2007 5:07 am    Post subject: Reply with quote

Novice

Joined: 21 Jun 2007
Posts: 24

ps. sorry the string I'm trying to CAST is '<SuperMods><MapData To="INM304_2006-07"><From>INM305_2006-07</From><From>INM306_2006-07</From></MapData><MapData To="INM332_2006-07"><From>IN2012_2006-07</From></MapData></SuperMods>'....however even a simplified string without attributes yields the same error
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Fri Jun 29, 2007 5:14 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Code:
SET CacheQueueBlob = CAST (xmlString AS BLOB CodedCharSetId InputRoot.Properties.CodedCharSetId);

_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » General Discussion » ESQL: Parsing a Character (XML string)
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.