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 » picking parts of XML tree

Post new topic  Reply to topic
 picking parts of XML tree « View previous topic :: View next topic » 
Author Message
Bingo
PostPosted: Mon Jun 27, 2005 2:43 am    Post subject: picking parts of XML tree Reply with quote

Novice

Joined: 31 Mar 2005
Posts: 22

Hi All,

I have this requirement. Please see the XML below.


<Test id=1>
<Name>AD</NAME>
</Test>
<Test id=2>
<Name>BC</NAME>
</Test>
<Test id=1>
<Name>AD</NAME>
</Test>

This is the output. However, client wants the Test id=1 to be unique in the output rather than repeating it twice(the complete Test id= tree). So if there are 2 Test id=1 then in the output the output XML needs to be something like below:


<Test id=1>
<Name>AD</NAME>
</Test>
<Test id=2>
<Name>BC</NAME>
</Test>

What is the best way to do it. Do we have any DISTINCT type keywords in E-SQL. What is the best way to handle this scenario ? Please suggest.

Regds,
Back to top
View user's profile Send private message
JT
PostPosted: Mon Jun 27, 2005 8:24 am    Post subject: Reply with quote

Padawan

Joined: 27 Mar 2003
Posts: 1564
Location: Hartford, CT.

Quote:
Do we have any DISTINCT type keywords in E-SQL.

No.

The best solution may be to prevent the duplicate entries from appearing in the Output tree in the first place:
Code:
DECLARE inIndex   INTEGER   1;
DECLARE outIndex  INTEGER   1;
DECLARE inRef     REFERENCE TO InputRoot.XML.ParentTag;
DECLARE inCount   INTEGER   CARDINALITY(inRef.Test[]);
CREATE FIELD OutputRoot.XML.ParentTag;
DECLARE outRef    REFERENCE TO OutputRoot.XML.ParentTag;

WHILE inIndex <=  inCount DO
   IF EXISTS(SELECT * FROM outRef.Test[] AS T WHERE T.(XML.Attribute)id = inRef.Test[inIndex].(XML.Attribute)id) THEN
   ELSE
      SET outRef.Test[outIndex] = inRef.Test[inIndex];
      SET outIndex  =  outIndex + 1;
   END IF;   
   SET inIndex  =  inIndex + 1;
END WHILE;


But, if that's un-avoidable, this should suffice:
Code:
DECLARE outRef  REFERENCE TO OutputRoot.XML.ParentTag;
DECLARE testRef REFERENCE TO outRef.Test;

WHILE LASTMOVE(testRef) = TRUE DO
   IF (SELECT COUNT(*) FROM outRef.Test[] AS T WHERE T.(XML.Attribute)id = testRef.(XML.Attribute)id) > 1 THEN
      DECLARE test2Ref REFERENCE TO testRef;
      MOVE testRef NEXTSIBLING;
      DETACH test2Ref;
   ELSE
      MOVE testRef NEXTSIBLING;
   END IF;
END WHILE;
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 » picking parts of XML tree
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.