Author |
Message
|
ccrandall |
Posted: Mon Aug 23, 2010 10:55 am Post subject: Root.XMLNSC always evaluates to NULL |
|
|
Acolyte
Joined: 23 Oct 2008 Posts: 52
|
With our upgrade to MB v7, I'm switching our code from using the XML to XMLNSC parser. One thing we were apparently allowed to get away with was doing something like the following:
IF InputRoot.XML IS NOT NULL...
If InputRoot.XML existed, it evaluated as NOT NULL. However, under XMLNSC, InputRoot.XMLNSC ALWAYS evaluates to NULL. So, I usually have to instead evaluate InputRoot.XMLNSC.(XMLNSC.Element)[1].
I'm trying to find why this behavior is different from XML to XMLNSC in the InfoCenter, but I haven't found what I'm looking for yet. If someone knows, could you help explain this or point me to the right resource?
Thanks!
Curt |
|
Back to top |
|
 |
Vitor |
Posted: Mon Aug 23, 2010 11:24 am Post subject: Re: Root.XMLNSC always evaluates to NULL |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
This is presumably the same set up as described here?
ccrandall wrote: |
I'm trying to find why this behavior is different from XML to XMLNSC in the InfoCenter, but I haven't found what I'm looking for yet. |
I'm not certain this is explicit in the InfoCenter anywhere, but the XMLNSC parser is much more strict (i.e. closer to the W3C standard) than the old one. So evaluating somthing like InputRoot.XML might work if the document could be parsed (though I'm slightly surprised it used to work) but the reference InputRoot.XMLNSC doesn't point to anything so you get a NULL back. By explicitly looking for the first element you get a result.
Not quite sure what you're checking for here (under either version). Under what circumstances did InputRoot.XML return NULL without the input node throwing a parsing error? What am I missing here? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
ccrandall |
Posted: Mon Aug 23, 2010 11:41 am Post subject: |
|
|
Acolyte
Joined: 23 Oct 2008 Posts: 52
|
Hi Vitor. That post you linked to is a different issue, but I'm sure they are related and it is for the same framework/application. I have a huge framework that has been using XML and I'm sure the way things were coded aren't kosher, but for the XML parser they work.
So, I'm currently retrofitting it to use XMLNSC and as a result of the parser being much more strict, simply replacing XML with XMLNSC in the ESQL leads to a lot of errors.
The framework I'm working on is kind of a "Swiss Army Knife" broker app. It can receive several data formats and typically they are transformed into an XML message and then sent on over MQ to a backend service. So, we have several chunks of code that might do something like:
IF Root.BLOB.BLOB IS NOT NULL THEN
...
ELSEIF Root.XML IS NOT NULL THEN
...
and so on. In my mind, the way XML (i.e. the parser) works seems more natural than XMLNSC. If Root.XML exists, then I would think it returns something other than NULL. I see your point about it really not pointing to anything and that's why it returns NULL... so for me I'm just getting used to a different mindset here.
I hope that all makes sense. Thank you for your help in clarifying this! |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Aug 23, 2010 11:49 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
I suspect that this is a tightening up in the ESQL code to check the VALUE of the node ponted to rather than whether it exists or not.
If you just want to find out of InputRoot.XMLNSC is defined, you can check that it has a non-null FIELDNAME. |
|
Back to top |
|
 |
rekarm01 |
Posted: Mon Aug 23, 2010 3:19 pm Post subject: Re: Root.XMLNSC always evaluates to NULL |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 1415
|
ccrandall wrote: |
With our upgrade to MB v7, I'm switching our code from using the XML to XMLNSC parser. One thing we were apparently allowed to get away with was doing something like the following:
IF InputRoot.XML IS NOT NULL... |
Upgrading from what? MQSI 2.0.2?
As of WMQI 2.1, "IS NOT NULL" only returns true if the referenced Field has a non-NULL value. It can't test for the existence of a Field with no value (or a NULL value).
ccrandall wrote: |
If InputRoot.XML existed, it evaluated as NOT NULL. However, under XMLNSC, InputRoot.XMLNSC ALWAYS evaluates to NULL. |
Not quite. By default, the XML parser retains mixed content, (such as the white space before and after child elements), but the XMLNSC parser does not. Remove the extraneous white space, and the test for InputRoot.XML will fail too.
ccrandall wrote: |
IF Root.BLOB.BLOB IS NOT NULL THEN
... |
Note the extra ".BLOB". Remove that, and that test will fail too.
mqjeff wrote: |
If you just want to find out of InputRoot.XMLNSC is defined, you can check that it has a non-null FIELDNAME. |
Or, check that is has a non-null FIELDTYPE. Or, use the EXISTS() function.
[Edit: changed "WBI MB 5.0" to "WMQI 2.1"]
Last edited by rekarm01 on Thu Apr 14, 2011 5:10 pm; edited 2 times in total |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Aug 23, 2010 3:50 pm Post subject: Re: Root.XMLNSC always evaluates to NULL |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
rekarm01 wrote: |
Or, use the EXISTS() function. |
I'm gonna have to disagree with your policework there, Lou.
I think the EXISTS operator and the EXISTS function both only apply to list expressions, and do not perform any tests for the reality or unreality of a node element. |
|
Back to top |
|
 |
rekarm01 |
Posted: Mon Aug 23, 2010 4:40 pm Post subject: Re: Root.XMLNSC always evaluates to NULL |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 1415
|
mqjeff wrote: |
I think the EXISTS operator and the EXISTS function both only apply to list expressions, and do not perform any tests for the reality or unreality of a node element. |
For the EXISTS() function, a ListExpression includes "A field reference with the [] array indicator":
Code: |
IF EXISTS(InputRoot.XMLNSC[]) THEN ... |
In that respect, it is similar to the CARDINALITY() function, and the SINGULAR() function. |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Aug 23, 2010 4:49 pm Post subject: Re: Root.XMLNSC always evaluates to NULL |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
rekarm01 wrote: |
mqjeff wrote: |
I think the EXISTS operator and the EXISTS function both only apply to list expressions, and do not perform any tests for the reality or unreality of a node element. |
For the EXISTS() function, a ListExpression includes "A field reference with the [] array indicator":
Code: |
IF EXISTS(InputRoot.XMLNSC[]) THEN ... |
In that respect, it is similar to the CARDINALITY() function, and the SINGULAR() function. |
InputRoot.XMLNSC[] offends my eyes - I do not want to consider the implications of that ever returning more than one. I'd be rather happier with InputRoot.XMLNSC.[].
I don't know what either will do if the message is actually in InputRoot.MRM. But I suspect it's not going to play nearly as nice as IS NOT NULL FIELDNAME(InputRoot.XMLNSC) will. I also strongly believe that FIELDNAME will be faster than EXISTS here.
To the other hand, if you've actually got production code running in v7 using this form of this expression, then I'll defer to your practical experience. |
|
Back to top |
|
 |
ccrandall |
Posted: Tue Aug 24, 2010 7:54 am Post subject: Re: Root.XMLNSC always evaluates to NULL |
|
|
Acolyte
Joined: 23 Oct 2008 Posts: 52
|
rekarm01 wrote: |
Upgrading from what? WMQI 2.1?
As of WBI MB 5.0, "IS NOT NULL" only returns true if the referenced Field has a non-NULL value. It can't test for the existence of a Field with no value (or a NULL value). |
Actually, this code has been running fine all the way up to version 7.0.0.0 while using the XML parser. It's only since I've been trying to transition to XMLNSC that I'm running into issues. Not that it's a bad thing... the code is better off now that it was. But like I said before, working with XMLNSC is requiring me to think differently than I was before when working with XML.
rekarm01 wrote: |
Not quite. By default, the XML parser retains mixed content, (such as the white space before and after child elements), but the XMLNSC parser does not. Remove the extraneous white space, and the test for InputRoot.XML will fail too.
|
It's odd that this code has been working fine under XML then. I don't believe there's any mixed content in most of the messages I'm handling. |
|
Back to top |
|
 |
ccrandall |
Posted: Tue Aug 24, 2010 7:56 am Post subject: |
|
|
Acolyte
Joined: 23 Oct 2008 Posts: 52
|
To resolve, I just changed these lines:
IF Root.XMLNSC IS NOT NULL
to:
IF FIELDNAME(Root.XMLNSC.(XMLNSC.Element)[1]) IS NOT NULL
After making the change, my unit tests all pass. Perhaps this isn't the best way to have done it, but if it works I'm going to stick with it.  |
|
Back to top |
|
 |
rekarm01 |
Posted: Tue Aug 24, 2010 11:09 pm Post subject: Re: Root.XMLNSC always evaluates to NULL |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 1415
|
ccrandall wrote: |
Actually, this code has been running fine all the way up to version 7.0.0.0 while using the XML parser. |
That's the problem with latent bugs. They work fine ... until they don't.
ccrandall wrote: |
It's odd that this code has been working fine under XML then. I don't believe there's any mixed content in most of the messages I'm handling. |
A Trace node could confirm that, one way or the other.
ccrandall wrote: |
IF FIELDNAME(Root.XMLNSC.(XMLNSC.Element)[1]) IS NOT NULL
After making the change, my unit tests all pass. Perhaps this isn't the best way to have done it, but if it works I'm going to stick with it. |
Fair enough. |
|
Back to top |
|
 |
|