Author |
Message
|
kash3338 |
Posted: Sat Sep 24, 2011 10:23 am Post subject: Query in SELECT ITEM function |
|
|
Shaman
Joined: 08 Feb 2009 Posts: 709 Location: Chennai, India
|
Hi,
I have an Input in which a particular element is repeating and the NAME value of each element is Unique. I need to fetch one particular NAME value and transform and map it to corresponding NAME in output. The Input and Output message are same except for this transformed value.
I use the SELECT ITEM statement to fetch the element using the WHERE clause. I need to know from which array subscript the element was fetched (the number). For example,
My Input:
<Root>
<EMP>
<Name>ABC</Name>
</EMP>
<EMP>
<Name>XYZ</Name>
</EMP>
<EMP>
<Name>DEF</Name>
</EMP>
</Root>
My Output:
<Root>
<EMP>
<Name>ABC</Name>
</EMP>
<EMP>
<Name>XYZ</Name>
</EMP>
<EMP>
<Name>DEF<TIMESTAMP></Name>
</EMP>
</Root>
My Input and Output are same, but for the element with Name as "DEF" I have to append the TIMESTAMP and send it.
I fetch the Value DEF using the SELECT ITEM function, but in Output I need to know the subscript so that I can directly insert the value to that subscript.
I copy the Entire message initially. This SELECT ITEM is done to avoid unnecessary loops in my code as the actual message is too large. Any suggestions will be helpful.
Also I would like to know if INSERT Selections will be helpful here? |
|
Back to top |
|
 |
fjb_saper |
Posted: Sat Sep 24, 2011 8:48 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
You mean to say you wouldn't be using references and move ref next sibling, if lastmove(ref) for your looping?  _________________ MQ & Broker admin |
|
Back to top |
|
 |
kash3338 |
Posted: Sat Sep 24, 2011 9:34 pm Post subject: |
|
|
Shaman
Joined: 08 Feb 2009 Posts: 709 Location: Chennai, India
|
fjb_saper wrote: |
You mean to say you wouldn't be using references and move ref next sibling, if lastmove(ref) for your looping?  |
I dont want to loop the XML since there would be lot of repeating elements and SELECT ITEM seems to be the best choice. But how do i get to know the Index where my element was found when using SELECT ITEM? |
|
Back to top |
|
 |
fjb_saper |
Posted: Sun Sep 25, 2011 7:08 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
It would help quite a bit, if you specified
What your input looks like (full path for repeat)
what your output looks like
your select statement
Why you need the row number of your DEF value.
I am still convinced that it would be far quicker to use a loop on a reference, moving it to next sibling until done..., especially if you have multiple DEF values in your output.
This can be done on the output.
Have you looked at the special index values for first, last etc...
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
kash3338 |
Posted: Sun Sep 25, 2011 8:33 am Post subject: |
|
|
Shaman
Joined: 08 Feb 2009 Posts: 709 Location: Chennai, India
|
fjb_saper wrote: |
Why you need the row number of your DEF value. |
I need this because my Input and Output are same except for adding timestamp for DEF alone.
fjb_saper wrote: |
I am still convinced that it would be far quicker to use a loop on a reference, moving it to next sibling until done..., especially if you have multiple DEF values in your output. |
I just have only one DEF in my Input for sure and hence SELECT is more efficient.
fjb_saper wrote: |
This can be done on the output.
Have you looked at the special index values for first, last etc... |
Can you please explain this more? |
|
Back to top |
|
 |
fjb_saper |
Posted: Sun Sep 25, 2011 12:47 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
kash3338 wrote: |
fjb_saper wrote: |
This can be done on the output.
Have you looked at the special index values for first, last etc... |
Can you please explain this more? |
the manual, look for [<], [>], [*] and their special meanings...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
Vitor |
Posted: Sun Sep 25, 2011 2:14 pm Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
fjb_saper wrote: |
the manual, look for [<], [>], [*] and their special meanings...  |
Rather assumes this DEF tag is in a known position (as I agree it is in the example shown). So if it's known to be the first, or the last, or the nth, then we're good.
But then I suspect the OP wouldn't have been made.
If it is indeed at some random position inside the document, your best best may well be to sacrifice the single select and loop as my worthy associate suggests. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
kash3338 |
Posted: Mon Sep 26, 2011 8:55 am Post subject: |
|
|
Shaman
Joined: 08 Feb 2009 Posts: 709 Location: Chennai, India
|
|
Back to top |
|
 |
mqjeff |
Posted: Mon Sep 26, 2011 9:49 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
I would suggest that this is a situation where use of an XPath expression would be of some value, but in general it might require that you use Java and if you don't know Java, then don't go down that road.
Also you should examine the notion of "unnecessary loops". For one thing, use of a SELECT may cause a loop to be performed under the covers. And so by using it, you are not avoiding a loop - you are merely avoiding the explicit statement of the loop.
For another thing, there is the whole question of what makes a loop necessary or unnecessary. |
|
Back to top |
|
 |
|