Author |
Message
|
KIT_INC |
Posted: Tue Dec 06, 2011 11:32 am Post subject: Is there a way to find XML tag using wildcard ? |
|
|
Knight
Joined: 25 Aug 2006 Posts: 589
|
We have to handle a large XML message from our branch office, There is a tag in the message that indicates the branch number. For example
<Message>
<AA>11</AA>
<BB>11</BB>
:
<BO123>BRANCH INFO </BO123>
:
<ZZ>11</ZZ>
</Message>
Where BO123 indicates branch office # 123.
We have 273 branch office, so that Tag can be BO001 to BO273.
Also this BOxxx tag can appear anywhere inside the xml file.
We want the broker to identify the branch office as soon as it receive the message. Any suggestion on how I can do it ?
I tried SET BR_OFFICE_NUM = InputRoot.XMLNSC.message.BO* with no luck.
I also looked at using Select, but I don't think it supports wildcard.
We are on WMB 61. If thre is no easy way in 61 , can WMB 70 do it ?better way ? |
|
Back to top |
|
 |
rekarm01 |
Posted: Tue Dec 06, 2011 1:45 pm Post subject: Re: Is there a way to find XML tag using wildcard ? |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 1415
|
KIT_INC wrote: |
I also looked at using Select, but I don't think it supports wildcard. |
SELECT supports a WHERE clause, which takes a boolean expression. The boolean LIKE operator supports pattern matching with wildcard characters. |
|
Back to top |
|
 |
kimbert |
Posted: Tue Dec 06, 2011 1:59 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
|
Back to top |
|
 |
lancelotlinc |
Posted: Tue Dec 06, 2011 2:22 pm Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
Quote: |
So I would use a JavaCompute node. |
And possibly toss in a Singleton for good measure / good dress.
JUST KIDDING! Vitor's Singleton  _________________ http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Dec 06, 2011 2:40 pm Post subject: Re: Is there a way to find XML tag using wildcard ? |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
rekarm01 wrote: |
KIT_INC wrote: |
I also looked at using Select, but I don't think it supports wildcard. |
SELECT supports a WHERE clause, which takes a boolean expression. The boolean LIKE operator supports pattern matching with wildcard characters. |
And you can probably use FIELDNAME from within WHERE. |
|
Back to top |
|
 |
KIT_INC |
Posted: Wed Dec 07, 2011 9:58 am Post subject: |
|
|
Knight
Joined: 25 Aug 2006 Posts: 589
|
I like to try using the select.. where.. method using a simple test message as shown.
<MSG>
<AA>11</AA>
<BB>22</BB>
<CC>33</CC>
<DD>44</DD>
<BO123>1234567</BO123>
<EE>55</EE>
<FF>66</FF>
<GG>77</GG>
</MSG>
I have difficulty using FIELDNAME in the where clause.
FIELDNAME is an ESQL function which requires 'source_field_reference'.
I cannot figure out what that should be
For example , I tried
SET Environment.DATA[]=(SELECT * FROM InputRoot.XMLNSC.MSG[] where FIELDNAME(InputRoot.XMLNSC.MSG.*) LIKE 'BO'; will not work. |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Dec 07, 2011 10:03 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You have to have the FIELDNAME operate on a specific field, not on a set of fields.
i.e. something perhaps like (*completely untested code may not function at all*)
Code: |
SELECT A.* FROM InputRoot.XMLNSC.MSG[] as A where FIELDNAME(A) LIKE 'BO' |
|
|
Back to top |
|
 |
KIT_INC |
Posted: Thu Dec 08, 2011 5:56 am Post subject: |
|
|
Knight
Joined: 25 Aug 2006 Posts: 589
|
I tried
SET Environment.DATA[] = SELECT A.* FROM InputRoot.XMLNSC.MSG[] as A where FIELDNAME(A) LIKE 'BO'
It did not fail during execution but the Environment was not set.
In debug, I can see all the XML TAGS under MSG in the tree under A. This means it takes the select A.* . But the where condition was not working and hence the Environment was not set. |
|
Back to top |
|
 |
Vitor |
Posted: Thu Dec 08, 2011 6:01 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
KIT_INC wrote: |
In debug, I can see all the XML TAGS under MSG in the tree under A. This means it takes the select A.* . But the where condition was not working and hence the Environment was not set. |
At the risk of sounding like a broken record, take a user trace. The debugger is showing you the snapshot; the XML tags before and the lack of Environment after. A user trace will show you how the where clause is being evaluated and matched, which may indicate why it's not matching what you think it should be matching.
Also (and accepting I'm only 1 cup of coffee into the morning) shouldn't it be '%BO%'? Or '*BO*'?
User trace. You take a user trace, I'll get more coffee. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mgk |
Posted: Thu Dec 08, 2011 6:02 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
You would need to use:
Regards, _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
Vitor |
Posted: Thu Dec 08, 2011 6:04 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
mgk wrote: |
You would need to use:
|
So that is WMB as well not just SQL! Thank you; got in that "I know I'm right but am I sure?" state of mind.
Still getting more coffee you understand. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Dec 08, 2011 6:07 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Vitor wrote: |
Still getting more coffee you understand. |
Fetch me a cuppa while you're up, won't you then?
Good lad. |
|
Back to top |
|
 |
KIT_INC |
Posted: Thu Dec 08, 2011 7:10 am Post subject: |
|
|
Knight
Joined: 25 Aug 2006 Posts: 589
|
I changed the ESQL SELECT to ( as suggested) and took the trace
SET Environment.DATA[]=(SELECT T.* FROM InputRoot.XMLNSC.MSG[] AS T WHERE FIELDNAME(T.*) LIKE 'BO%');
2011-12-08 09:55:22.348028 5292 UserTrace BIP2538I: Node 'TEST_WILDCARD_FIELDNAME.Compute': Evaluating expression ''(SELECT T.*:* FROM InputRoot.XMLNSC.MSG[ ] AS T WHERE FIELDNAME(T.*:*) LIKE 'BO%')'' at ('.TEST_WILDCARD_FIELDNAME_Compute.CopyEntireMessage', '34.34').
2011-12-08 09:55:22.348215 5292 UserTrace BIP2573W: Node 'TEST_WILDCARD_FIELDNAME.Compute': ('.TEST_WILDCARD_FIELDNAME_Compute.CopyEntireMessage', '34.34') : Finding first SELECT result.
2011-12-08 09:55:22.354417 5292 UserTrace BIP2539I: Node 'TEST_WILDCARD_FIELDNAME.Compute': Evaluating expression ''InputRoot.XMLNSC.MSG[ ]'' at ('.TEST_WILDCARD_FIELDNAME_Compute.CopyEntireMessage', '34.43'). This resolved to ''InputRoot.XMLNSC.MSG[]''. The result was ''LIST... First Element Type=16777216 NameSpace='' Name='MSG' Value=NULL''.
2011-12-08 09:55:22.355169 5292 UserTrace BIP2540I: Node 'TEST_WILDCARD_FIELDNAME.Compute': Finished evaluating expression ''FIELDNAME(T.*:*)'' at ('.TEST_WILDCARD_FIELDNAME_Compute.CopyEntireMessage', '34.77'). The result was '''AA'''.
2011-12-08 09:55:22.355318 5292 UserTrace BIP2539I: Node 'TEST_WILDCARD_FIELDNAME.Compute': Evaluating expression ''FIELDNAME(T.*:*) LIKE 'BO%''' at ('.TEST_WILDCARD_FIELDNAME_Compute.CopyEntireMessage', '34.92'). This resolved to '''AA' LIKE 'BO%' ESCAPE '\'''. The result was ''FALSE''.
2011-12-08 09:55:22.355348 5292 UserTrace BIP2569W: Node 'TEST_WILDCARD_FIELDNAME.Compute': ('.TEST_WILDCARD_FIELDNAME_Compute.CopyEntireMessage', '34.34') : WHERE clause evaluated to false or unknown. Iterating FROM clause.
It picks up the first TAG 'AA' and compare it with BO% and stops when no match.
I change my input message with BO123 as the first XML TAG, it found a match and set the environment.
Any idea how to get it to continue after the first match is a false ? |
|
Back to top |
|
 |
Vitor |
Posted: Thu Dec 08, 2011 7:31 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
KIT_INC wrote: |
Any idea how to get it to continue after the first match is a false ? |
Why have you got FIELDNAME(T.*) rather than the FIELDNAME(T)? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
KIT_INC |
Posted: Thu Dec 08, 2011 8:07 am Post subject: |
|
|
Knight
Joined: 25 Aug 2006 Posts: 589
|
I did try 'WHERE FIELDNAME(T) LIKE 'BO%'
But it will not even compare the first TAG "AA", instead it is comparing MSG (The root tag).
2011-12-08 11:03:23.671991 1240 UserTrace BIP2539I: Node 'TEST_WILDCARD_FIELDNAME.Compute': Evaluating expression ''InputRoot.XMLNSC.MSG[ ]'' at ('.TEST_WILDCARD_FIELDNAME_Compute.CopyEntireMessage', '34.43'). This resolved to ''InputRoot.XMLNSC.MSG[]''. The result was ''LIST... First Element Type=16777216 NameSpace='' Name='MSG' Value=NULL''.
2011-12-08 11:03:23.672506 1240 UserTrace BIP2540I: Node 'TEST_WILDCARD_FIELDNAME.Compute': Finished evaluating expression ''FIELDNAME(T)'' at ('.TEST_WILDCARD_FIELDNAME_Compute.CopyEntireMessage', '34.77'). The result was '''MSG'''.
2011-12-08 11:03:23.672645 1240 UserTrace BIP2539I: Node 'TEST_WILDCARD_FIELDNAME.Compute': Evaluating expression ''FIELDNAME(T) LIKE 'BO%''' at ('.TEST_WILDCARD_FIELDNAME_Compute.CopyEntireMessage', '34.90'). This resolved to '''MSG' LIKE 'BO%' ESCAPE '\'''. The result was ''FALSE''.
2011-12-08 11:03:23.672670 1240 UserTrace BIP2569W: Node 'TEST_WILDCARD_FIELDNAME.Compute': ('.TEST_WILDCARD_FIELDNAME_Compute.CopyEntireMessage', '34.34') : WHERE clause evaluated to false or unknown. Iterating FROM clause. |
|
Back to top |
|
 |
|