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 » How browse an XML message in ESQL ?

Post new topic  Reply to topic
 How browse an XML message in ESQL ? « View previous topic :: View next topic » 
Author Message
unilog
PostPosted: Tue Apr 30, 2002 7:45 am    Post subject: Reply with quote

Novice

Joined: 29 Apr 2002
Posts: 17
Location: Paris, France

Hello,

I want to find in an XML message all tags that have a certain name.
Is anybody have an idea ?

Exemple : in this message, i want to find the 2 instances of the 'mytag', so i can - for exemple - add subtags to theses 'mytag'

<message>
<content>
<mytag>
<sub-message>
<mytag></mytag>
</sub-message>
</mytag>
</content>
</message>

I try CARDINALITY and REFERENCES with LASTMOVE(), but i doesn't seems to works ?!?
Back to top
View user's profile Send private message
Ward
PostPosted: Tue Apr 30, 2002 8:54 am    Post subject: Reply with quote

Voyager

Joined: 27 Jun 2001
Posts: 98
Location: Europe

Hi,

Think something like this should do the trick...

SET OutputRoot = InputRoot;
-- Enter SQL below this line. SQL above this line might be regenerated, causing any modifications to be lost.
DECLARE I INTEGER ;
SET I = 1 ;
WHILE ( I <= CARDINALITY( InputRoot.XML.MESSAGE.CONTENT.MYTAG[] ) ) DO
SET OutputRoot.XML.MESSAGE.CONTENT.MYTAG[I].YOURNEWSUBTAG = 'WHATEVER' ;
SET I = I + 1 ;
END WHILE ;


Cheers,

Ward.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
unilog
PostPosted: Tue Apr 30, 2002 9:33 am    Post subject: Reply with quote

Novice

Joined: 29 Apr 2002
Posts: 17
Location: Paris, France

Thanks for your help, but your solution only works if all the 'mytag' are on the same level !!!

As you see on our example, the 2 instances are not on the same level (actually, the real message is dynamic, so we don't know where are the tag) !

So have you an idea to scan a tag in a whole XML message ???
Back to top
View user's profile Send private message
Ward
PostPosted: Wed May 01, 2002 1:03 am    Post subject: Reply with quote

Voyager

Joined: 27 Jun 2001
Posts: 98
Location: Europe

Hiya,

Well you can use wildcard within XML... something like InputRoot.XML.*.*.MYTAG but you'll need to know the maximum level of nesting and then look on each level for the cardinality etc etc... I know not very nice but probably the only way...

Regards,

Ward.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
amigupta1978
PostPosted: Wed May 01, 2002 5:23 am    Post subject: Reply with quote

Centurion

Joined: 22 Jan 2002
Posts: 132
Location: India

Hi,
U can use the reference variables for doing this. But this will work only in WMQI 2.1
I have not tested it but I think this shud work.

DECLARE refRoot to InputRoot;
Move xref to InputRoot.XML
done =0;
While (LASTMOVE(xref) and done=0) do

If Fieldname(xref)='YOUR TAG' then
do processing
end if;

MOVE xref to FIRSTCHILD
IF NOT LASTMOVE(xref) THEN
MOVE XREF to PARENT; -- definitely have parent
MOVE XREF to NEXTSIBLING;
WHILE ( NOT LASTMOVE(XREF) and (done=0))
MOVE XREF TO PARENT;
If samefield (xref,refRoot) THEN
done = 1;
end if;
MOVE XREF to NEXTSIBLING;
END WHILE;


END IF;
END WHILE;

Regards,
Amit
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
unilog
PostPosted: Thu May 02, 2002 10:39 am    Post subject: Reply with quote

Novice

Joined: 29 Apr 2002
Posts: 17
Location: Paris, France

Hi and thanks for your help, i have made some corrections on your script and yes it's run (under WMQI 2.1)

This script scan all the XML message and when it find a tag called 'mytag', it add it a child called 'NewSubTag' :

DECLARE refRoot REFERENCE TO OutputRoot;
DECLARE xref REFERENCE TO OutputRoot.XML.Content;
DECLARE done INTEGER;
SET done=0;

While (LASTMOVE(xref) and done=0) do
If Fieldname(xref)='mytag' then
CREATE FIRSTCHILD OF xref NAME 'NewSubTag' VALUE 'well I am new';
end if;

MOVE xref FIRSTCHILD;
IF NOT LASTMOVE(xref) THEN
MOVE xref NEXTSIBLING;
WHILE ( NOT LASTMOVE(xref) and (done=0)) do
MOVE xref PARENT;
If samefield (xref,refRoot) THEN
SET done = 1;
end if;
MOVE xref NEXTSIBLING;
END WHILE;
END IF;
END WHILE;

This is the french XML message we send :
<Content><Contrat><mytag>test2</mytag><Type>Marché</Type></Contrat><mytag>test1</mytag></Content>

And this is the result we get :
<Content><Contrat><mytag><NewSubTag>well I am new</NewSubTag>test2</mytag><Type>Marché</Type></Contrat><mytag><NewSubTag>well I am new</NewSubTag>test1</mytag></Content>

That works great, thanks a lot !

Unilog(MSTU)
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 » WebSphere Message Broker (ACE) Support » How browse an XML message 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.