Author |
Message
|
emqueuer |
Posted: Thu Jun 28, 2007 3:36 am Post subject: ESQL: Parsing a Character (XML string) |
|
|
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 |
|
 |
special_agent_Queue |
Posted: Thu Jun 28, 2007 4:52 am Post subject: |
|
|
 Centurion
Joined: 27 Jul 2006 Posts: 102
|
check out the CREATE...PARSE statement. |
|
Back to top |
|
 |
emqueuer |
Posted: Fri Jun 29, 2007 1:48 am Post subject: |
|
|
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 |
|
 |
fjb_saper |
Posted: Fri Jun 29, 2007 3:06 am Post subject: |
|
|
 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 |
|
 |
emqueuer |
Posted: Fri Jun 29, 2007 5:01 am Post subject: |
|
|
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 |
|
 |
emqueuer |
Posted: Fri Jun 29, 2007 5:03 am Post subject: |
|
|
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 |
|
 |
emqueuer |
Posted: Fri Jun 29, 2007 5:07 am Post subject: |
|
|
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 |
|
 |
jefflowrey |
Posted: Fri Jun 29, 2007 5:14 am Post subject: |
|
|
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 |
|
 |
|