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 » WebSphere Message Broker (ACE) Support » Dynamic XML Tag to FIX XML TAG..............................

Post new topic  Reply to topic
 Dynamic XML Tag to FIX XML TAG.............................. « View previous topic :: View next topic » 
Author Message
geiger
PostPosted: Tue Jun 11, 2002 5:37 am    Post subject: Dynamic XML Tag to FIX XML TAG.............................. Reply with quote

Newbie

Joined: 11 Jun 2002
Posts: 2

i have han XML with different input in a special tag (dynamic) and i want an fix output in XML:

Input File:

<XML>
<TAG1>xxxxx</TAG1>
<TAG2>field2;field3;EMPTY;Field4>
<XML>

Output File:
<XML>
<TAG1>xxxxx</TAG1>
<TAG2>
<FIELD1>field1</FIELD1>
<FIELD2>field2</FIELD2>
<FIELD3></FIELD3>
<FIELD4>field4</FIELD4>
</TAG2>
</XML>

thanks for your help.

Bruno
Back to top
View user's profile Send private message Send e-mail
TorpedoSTu
PostPosted: Wed Jun 12, 2002 12:40 am    Post subject: Reply with quote

Acolyte

Joined: 14 Nov 2001
Posts: 73

use the position function to parse your input XML element and the 'eval' function construct your output. - The ESQL reference guide gives good examples

i.e.

(pseudo)
declare cnt int
declare invar character
declare outvar character
declare fname character
set fname = 'FIELD'
set invar = XMLElement
start = 1
WHILE pos < len(invar)
pos = position(';',invar)
if pos > 0 then
set outvar = substring(invar,1,pos-1) - get data within ';'s
set invar = substring(invar,pos+1) - remove what we've just substringed
set cnt = cnt + 1
use 'eval' statement to create op element using outvar & cnt
pos = 0
endif
loop
if len(invar) > 0 -- we've still got to pick up the last one
set cnt = cnt + 1
use 'eval' statement to create op element using invar & cnt
end if

If there are special cases like EMPTY, then you can code to suit

Hope this helps

Stu
Back to top
View user's profile Send private message Send e-mail
geiger
PostPosted: Fri Jun 14, 2002 2:28 am    Post subject: Running version for Dynamic XML to FIX XML Reply with quote

Newbie

Joined: 11 Jun 2002
Posts: 2

This is one result of my test.....................................!!!!

Bruno


SET OutputRoot.XML.XML.TAG2 = InputRoot.XML.XML.TAG2;

DECLARE InputData INTEGER;
DECLARE OutputData INTEGER;

DECLARE POS INTEGER;
DECLARE V1 CHAR;

DECLARE FELD1 CHAR;
DECLARE FELD2 CHAR;
DECLARE FELD3 CHAR;
DECLARE FELD4 CHAR;




SET I=1;

SET V1 = SUBSTRING(InputRoot.XML.XML.TAG2 FROM 1 FOR 40);
SET POS = POSITION(';' IN V1);


IF(POS>0)
-- Wenn ein ; gefunden wurde, wird bis zum ; der Inhalt in die Variable FELD1 kopiert
THEN SET FELD1 = SUBSTRING(V1 FROM 1 FOR (POS -1));
ELSE SET FELD1 = '';
END IF;

SET V1 = SUBSTRING(V1 FROM POS+1);
SET POS = POSITION(';' IN V1);

IF(POS>0)
-- Wenn ein ; gefunden wurde, wird bis zum ; der Inhalt in die Variable FELD2 kopiert
THEN SET FELD2 = SUBSTRING(V1 FROM 1 FOR(POS -1));
ELSE SET FELD2 = '';
END IF;

SET V1 = SUBSTRING(V1 FROM POS+1);
SET POS = POSITION(';' IN V1);

IF(POS>0)
-- Wenn ein ; gefunden wurde, wird bis zum ; der Inhalt in die Variable FELD3 kopiert
THEN SET FELD3 = SUBSTRING(V1 FROM 1 FOR(POS -1));
ELSE SET FELD3 = '';
END IF;

SET V1 = SUBSTRING(V1 FROM POS+1);
SET POS = POSITION(';' IN V1);

IF V1<>''
-- Wenn ein ; gefunden wurde, wird bis zum ; der Inhalt in die Variable FELD4 kopiert
THEN SET FELD4 = SUBSTRING(V1 FROM 1);
ELSE SET FELD4 = '';
END IF;

SET OutputRoot.XML.XML.TAG1 = InputRoot.XML.XML.TAG1;

SET OutputRoot.XML.XML.TAG2.FIELD1 = FELD1;
SET OutputRoot.XML.XML.TAG2.FIELD2 = FELD2;
SET OutputRoot.XML.XML.TAG2.FIELD3 = FELD3;
SET OutputRoot.XML.XML.TAG2.FIELD4 = FELD4;
Back to top
View user's profile Send private message Send e-mail
TorpedoSTu
PostPosted: Fri Jun 14, 2002 3:47 am    Post subject: Reply with quote

Acolyte

Joined: 14 Nov 2001
Posts: 73

Bruno,

OK you've done it explicitly by only expecting 4 substrings within TAG2, that's OK if there will only ever be 4 entries (i.e. FIELD1, FIELD2, FIELD3, FIELD4). If there are more then I suggest you put in a loop and use the EVAL function.

You've also allowed for InputRoot.XML.TAG2 to be 40 characters
try changing the Set of V1 to be as follows ....

SET V1 = InputRoot.XML.TAG2

I can't see the test for EMPTY in there as per your original question.

I suggest changing as follws ...


SET POS = POSITION('EMPTY',FELD1)
IF POS > 0 THEN
SET OutputRoot.XML.XML.TAG2.FIELD1 = '';
ELSE
SET OutputRoot.XML.XML.TAG2.FIELD1 = FELD1;
END IF;

SET POS = POSITION('EMPTY',FELD2)
IF POS > 0 THEN
SET OutputRoot.XML.XML.TAG2.FIELD2 = '';
ELSE
SET OutputRoot.XML.XML.TAG2.FIELD2 = FELD2;
END IF;

SET POS = POSITION('EMPTY',FELD3)
IF POS > 0 THEN
SET OutputRoot.XML.XML.TAG2.FIELD3 = '';
ELSE
SET OutputRoot.XML.XML.TAG2.FIELD3 = FELD3;
END IF;

SET POS = POSITION('EMPTY',FELD4)
IF POS > 0 THEN
SET OutputRoot.XML.XML.TAG2.FIELD4 = '';
ELSE
SET OutputRoot.XML.XML.TAG2.FIELD4 = FELD4;
END IF;

Let me know if you need the EVAL function version & I'll code it for you.

Regs

Stuart
Back to top
View user's profile Send private message Send e-mail
TorpedoSTu
PostPosted: Fri Jun 14, 2002 4:25 am    Post subject: Reply with quote

Acolyte

Joined: 14 Nov 2001
Posts: 73

Bruno

Here's the version that I had in mind .....

DECLARE I INTEGER;
SET I = 1;
WHILE I < CARDINALITY(InputRoot.*[]) DO
SET OutputRoot.*[I] = InputRoot.*[I];
SET I=I+1;
END WHILE;
-- Enter SQL below this line. SQL above this line might be regenerated, causing any modifications to be lost.
DECLARE CNT INTEGER;
DECLARE POS INTEGER;
DECLARE INVAR CHARACTER;
DECLARE OUTVAR CHARACTER;
SET INVAR = InputRoot.XML.XML.TAG2;
SET CNT = 0;
SET POS = 9999;
WHILE POS > 0 DO
SET POS = POSITION(';' IN INVAR);
IF POS > 0 THEN
SET OUTVAR = SUBSTRING(INVAR FROM 1 FOR POS-1);
IF OUTVAR = 'EMPTY' THEN
SET OUTVAR = '';
END IF;
SET INVAR = SUBSTRING(INVAR FROM POS+1);
SET CNT = CNT + 1;
EVAL('SET OutputRoot.XML.XML.FIELD' || CAST(CNT AS CHARACTER) || ' = OUTVAR;');
END IF;
END WHILE;
IF LENGTH(INVAR) > 0 THEN
IF OUTVAR = 'EMPTY' THEN
SET OUTVAR = '';
END IF;
SET CNT = CNT + 1;
EVAL('SET OutputRoot.XML.XML.FIELD' || CAST(CNT AS CHARACTER) || ' = INVAR;');
END IF;


An Input Message of .....

<XML><TAG1>xxxxx</TAG1><TAG2>field1;field2;EMPTY;Field4</TAG2><XML>

Gives .....

<XML><FIELD1>field1</FIELD1><FIELD2>field2</FIELD2><FIELD3></FIELD3><FIELD4>Field4</FIELD4></XML>

Regs

Stuart
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Dynamic XML Tag to FIX XML TAG..............................
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.