Author |
Message
|
deepak_paul |
Posted: Wed Oct 05, 2011 7:24 am Post subject: Get all instances of an element in XML using ESQL |
|
|
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 |
|
 |
MrSmith |
Posted: Wed Oct 05, 2011 7:51 am Post subject: |
|
|
 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 |
|
 |
deepak_paul |
Posted: Wed Oct 05, 2011 11:53 am Post subject: |
|
|
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 |
|
 |
deepak_paul |
Posted: Thu Oct 06, 2011 3:49 am Post subject: |
|
|
Centurion
Joined: 04 Oct 2008 Posts: 147 Location: US
|
Any other suggestions on how we can solve this? _________________ Regards
Paul |
|
Back to top |
|
 |
paintpot |
Posted: Thu Oct 06, 2011 4:19 am Post subject: |
|
|
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 |
|
 |
mqjeff |
Posted: Thu Oct 06, 2011 6:03 am Post subject: |
|
|
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 |
|
 |
MrSmith |
Posted: Thu Oct 06, 2011 2:18 pm Post subject: |
|
|
 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 |
|
 |
j.f.sorge |
Posted: Thu Oct 06, 2011 8:29 pm Post subject: |
|
|
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 |
|
 |
deepak_paul |
Posted: Sun Oct 23, 2011 9:51 am Post subject: |
|
|
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 |
|
 |
|