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 » Get all instances of an element in XML using ESQL

Post new topic  Reply to topic
 Get all instances of an element in XML using ESQL « View previous topic :: View next topic » 
Author Message
deepak_paul
PostPosted: Wed Oct 05, 2011 7:24 am    Post subject: Get all instances of an element in XML using ESQL Reply with quote

Centurion

Joined: 04 Oct 2008
Posts: 147
Location: US

All,

Requirement: Get the Xpath of an element dynamically from Database and validate(check if null or empty) the element in all occurrences of the Input message.

i.e.
Code:

<Msg>
   <X>
       <Y>
          <Z>
             <M><!--ValueofM--></M>
          </Z>
          <Z>
             <M><!--ValueofM--></M>
             <M><!--ValueofM--></M>
          </Z>
       </Y>
       <Y>
          <Z>
             <M><!--ValueofM--></M>
          </Z>
       </Y>
       <Y>
          <Z>
             <N><!--ValueofN--></N>
          </Z>
       </Y>
   </X>
   <X>
       <Y>
          <Z>
             <M><!--ValueofM--></M>
             <M><!--ValueofM--></M>
          </Z>
       </Y>
   </X>
</Msg>


The current approach is:

1. Get the XPath of the element from DB. (i.e Msg/X/Y/Z/M)
2. Evaluate the Xpath (using EVAL()) and check the value (to see if M is null or M is empty)

But the problem is that the approach always checks first occurance of all its parent but we need to check to see all occurrences of M in all its parents (i.e Msg.X[1...i].Y[1...j].Z[1...k].M[1...l].)

Note: the XPath is dynamically retrieved from Database. So the parent level is not always consistent. For instance, for other element J, i may have XPath as Msg.M.N.P.O.K.J and have to validate Msg.M[1...a].N[1...b].P[1...c].O[1...d].K[1...e].J[1..f].

The workarounds:
Code:
Msg.*.*.*.M; did not give me the expected result nor throwing the exception as i believe we can use * for only one level(Msg.*.E for Msg.H.E or Msg.J.E) not for multiple levels;


Any approach in ESQL to get this around? Thanks.
_________________
Regards
Paul
Back to top
View user's profile Send private message
MrSmith
PostPosted: Wed Oct 05, 2011 7:51 am    Post subject: Reply with quote

Master

Joined: 20 Mar 2008
Posts: 215

Well you can use the negative approach by checking to see if any of the structures you have DONT have the required M elements by doing a SELECT and count statement over the structure then if your count is greater than zero you got a problem Euston!!!! The problem will be the dynamic path you require though you might try with Sub-selects and having clauses
Back to top
View user's profile Send private message
deepak_paul
PostPosted: Wed Oct 05, 2011 11:53 am    Post subject: Reply with quote

Centurion

Joined: 04 Oct 2008
Posts: 147
Location: US

MrSmith wrote:
Well you can use the negative approach by checking to see if any of the structures you have DONT have the required M elements by doing a SELECT and count statement over the structure then if your count is greater than zero you got a problem Euston!!!! The problem will be the dynamic path you require though you might try with Sub-selects and having clauses


As suggested, I am trying out with SELECT but no expected results as of now.

Can you elaborate how to do with SUBSELECTS?
_________________
Regards
Paul
Back to top
View user's profile Send private message
deepak_paul
PostPosted: Thu Oct 06, 2011 3:49 am    Post subject: Reply with quote

Centurion

Joined: 04 Oct 2008
Posts: 147
Location: US

Any other suggestions on how we can solve this?
_________________
Regards
Paul
Back to top
View user's profile Send private message
paintpot
PostPosted: Thu Oct 06, 2011 4:19 am    Post subject: Reply with quote

Centurion

Joined: 19 Sep 2005
Posts: 112
Location: UK

There may be a clever way, but it is tempting to use a series of embedded loops, driven by ESQL, looking for the fieldnames from your XPATH. I suspect it would be efficient at least (e.g. you haven't described the size of the message coming in).

Sometimes the old ways are still the best ways - handcraft it.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Thu Oct 06, 2011 6:03 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

This is the kind of thing where an ESQL function to EVALUATEXPATH would be useful.

The XPath expression language automatically tends to match all elements across the entire document.

So you might consider using a Java procedure or a JCN and using evaluateXPath() from there to accomplish this.

Or you can look at using a SELECT on FIELDNAME and see if that lets you match all 'M' across the document. I can't say it will, though.
Back to top
View user's profile Send private message
MrSmith
PostPosted: Thu Oct 06, 2011 2:18 pm    Post subject: Reply with quote

Master

Joined: 20 Mar 2008
Posts: 215

Another thought not sure if its possible but try it out - COALEASCE will look for the first occurence of an element within a oath so why not and IF NOT COALESCE to see if there isnt one?
Back to top
View user's profile Send private message
j.f.sorge
PostPosted: Thu Oct 06, 2011 8:29 pm    Post subject: Reply with quote

Master

Joined: 27 Feb 2008
Posts: 218

Probably using REFERENCES could help here. MOVE it (e. g. WHILE in a loop until LASTMOVE) to the first element with the given name and then go deeper into the tree for each element given in the XPath expression. Use of REPEAT NAME may help you after you got one element with the given name.
_________________
IBM Certified Solution Designer - WebSphere MQ V6.0
IBM Certified Solution Developer - WebSphere Message Broker V6.0
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0
Back to top
View user's profile Send private message
deepak_paul
PostPosted: Sun Oct 23, 2011 9:51 am    Post subject: Reply with quote

Centurion

Joined: 04 Oct 2008
Posts: 147
Location: US

Yes, j.f.sorge. I have done this with maximum use of REFERENCE and MOVE statements. It works. This is resolved.

Thank you.
_________________
Regards
Paul
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 » Get all instances of an element in XML using 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.