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 » Test for existence of a path within an xml message

Post new topic  Reply to topic Goto page 1, 2  Next
 Test for existence of a path within an xml message « View previous topic :: View next topic » 
Author Message
Blobtastic
PostPosted: Tue Apr 20, 2004 1:38 am    Post subject: Test for existence of a path within an xml message Reply with quote

Apprentice

Joined: 03 Nov 2003
Posts: 34
Location: uk

Hi,

Sorry if this is a bit elementary for anyone that reads this, but I'm neither an WMQI or XML expert, and I'm struggling to test for the existence of a path within a message.

I'm (rightly or wrongly) trying to use a filter node to test this. I'm testing on 'IS NULL', which works when the path exists, but goes to 'Unknown' terminal when it doesn't. I'm assuming it would be cleaner to get a TRUE or FALSE response, but I don't know how to trap it.

Any ideas?

Many thanks


My example:-

Filter node code:
.......TEST.DATA1 IS NULL

The message

<TEST>
<DATA1>example</DATA1>
</TEST>

goes to the FALSE output, which I think is correct, however, the message

<TEST>
<DATA2>example</DATA2>
</TEST>

goes to the UNKOWN terminal.

Is this the correct test, or is there a better way? I'm kinda assuming there is!

many thanks

Blobby
Back to top
View user's profile Send private message
fschofer
PostPosted: Tue Apr 20, 2004 3:13 am    Post subject: Reply with quote

Knight

Joined: 02 Jul 2001
Posts: 524
Location: Mainz, Germany

Hi,
you can use the CARDINALITY funktion to get the number of path element

IF CARDINALITY (.......TEST.DATA1 ) = 0

Greetings
Frank
Back to top
View user's profile Send private message Send e-mail
Blobtastic
PostPosted: Tue Apr 20, 2004 3:18 am    Post subject: Reply with quote

Apprentice

Joined: 03 Nov 2003
Posts: 34
Location: uk

Thanks Frank,

Sounds good. I'll give it a try, and report back!

many thanks
Back to top
View user's profile Send private message
fazz
PostPosted: Tue Apr 20, 2004 3:53 am    Post subject: Reply with quote

Centurion

Joined: 20 Feb 2004
Posts: 144
Location: England

Hi,

You could use the FIELDNAME function.
This returns the name of the field if it exists or an empty string if not.

i.e.

IF FIELDNAME(Root.TEST.DATA1) = '' THEN

Fazz
Back to top
View user's profile Send private message
Blobtastic
PostPosted: Tue Apr 20, 2004 5:32 am    Post subject: Reply with quote

Apprentice

Joined: 03 Nov 2003
Posts: 34
Location: uk

Thanks guys.

In either case, what am I setting to 0 or 1?

If <test condition> THEN
[i]what?[/i]
ELSE
[i]what?[/i]
END IF;

Many thanks
Back to top
View user's profile Send private message
JT
PostPosted: Tue Apr 20, 2004 6:52 am    Post subject: Reply with quote

Padawan

Joined: 27 Mar 2003
Posts: 1564
Location: Hartford, CT.

Blobtastic,
I assumed you were at v5.x based on your previous postings. If so, try this in your Filter module:
Code:
IF Root.XML.TEST.DATA1 IS NULL THEN
   RETURN TRUE;
ELSE
   RETURN FALSE;
END IF;
Back to top
View user's profile Send private message
Blobtastic
PostPosted: Tue Apr 20, 2004 7:07 am    Post subject: Reply with quote

Apprentice

Joined: 03 Nov 2003
Posts: 34
Location: uk

Thanks all, but.....

I tried all three of your suggestions :-

IF CARDINALITY(Body.TEST.DATA1[]) = 0 THEN
RETURN FALSE;
ELSE
RETURN TRUE;
END IF;


and


IF FIELDNAME(Body.TEST.DATA1) = '' THEN
RETURN FALSE;
ELSE
RETURN TRUE;
END IF;


and


IF Root.XML.TEST.DATA1 IS NULL THEN
RETURN FALSE;
ELSE
RETURN TRUE;
END IF;

which I think covers all the suggestions.

All three work for one test, but in all cases the alternative is UNKNOWN, which is where I started. I'm using v2.1.

Am I missing something simple?
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Tue Apr 20, 2004 7:11 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Code:
--UNTESTED
if (COALESCE(Body.TEST.DATA1,0) = 0) then
      return false;
else
      return true;
end if;

_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
Blobtastic
PostPosted: Tue Apr 20, 2004 7:15 am    Post subject: Reply with quote

Apprentice

Joined: 03 Nov 2003
Posts: 34
Location: uk

Sadly not Jeff (same results as other attempts), but it gives me some more ideas and things I can try. I can't believe this is soooo difficult.

many thanks everyone
Back to top
View user's profile Send private message
JT
PostPosted: Tue Apr 20, 2004 7:37 am    Post subject: Reply with quote

Padawan

Joined: 27 Mar 2003
Posts: 1564
Location: Hartford, CT.

V2.1 ESQL Reference Manual page 79 wrote:
When used in a Filter, Compute, or Database node’s mainline code, the RETURN
statement causes execution of the node’s ESQL to cease and for control to be
passed to the next node. In these cases, if "expression" is present, it must evaluate
to a BOOLEAN value. If "expression" is not present, a Filter node assumes a value
of UNKNOWN and propagates to its unknown terminal
, but Compute and
Database nodes propagate to their out terminals.

Just trying to eliminate the obvious, but are your specifically qualifying the RETURN statement? Have you turned on a debug-level trace to see how the statements in your Filter node are being evaluated. This will clarify whether the IF statement of RETURN is producing the UNKNOWN condition.
Back to top
View user's profile Send private message
Empeterson
PostPosted: Tue Apr 20, 2004 12:23 pm    Post subject: Reply with quote

Centurion

Joined: 14 Apr 2003
Posts: 125
Location: Foxboro, MA

Since you are using a filter node, wouldnt just putting in the expression code work. For instance:

CARDINALITY(Body.TEST.DATA1[]) >= 0;


No need to do the IF THEN ELSE. The above would return TRUE if it exists, FALSE if it does not.
_________________
IBM Certified Specialist: MQSeries
IBM Certified Specalist: Websphere MQ Integrator
Back to top
View user's profile Send private message Send e-mail AIM Address
mgk
PostPosted: Wed Apr 21, 2004 12:08 am    Post subject: Reply with quote

Padawan

Joined: 31 Jul 2003
Posts: 1642

Using CARDINALITY will be slow as it has to try to count all the elements called DATA1, which implies scanning all children of TEST.

A faster way to test for the existence of a field is:

EXISTS( SELECT * FROM Body.TEST.DATA1[] );
Which breaks early as soon as the SELECT returns a result.

Another candidate not mentioned on this thread is:

FIELDTYPE( Body.TEST.DATA1 ) IS NULL;

Cheers,
_________________
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
View user's profile Send private message
leongor
PostPosted: Wed Apr 21, 2004 2:06 am    Post subject: Reply with quote

Master

Joined: 13 May 2002
Posts: 264
Location: Israel

Quote:

Code:
--UNTESTED
if (COALESCE(Body.TEST.DATA1,0) = 0) then
return false;
else
return true;
end if;

If I remember right I did it once that way :
Quote:

if (COALESCE( NULLIF(Body.TEST.DATA1,NULL), 0) = 0) then
return false;
else
return true;
end if;

Hope it still works.
_________________
Regards.
Leonid.

IBM Certified MQSeries Specialist.
Back to top
View user's profile Send private message
Blobtastic
PostPosted: Thu Apr 22, 2004 2:05 am    Post subject: Reply with quote

Apprentice

Joined: 03 Nov 2003
Posts: 34
Location: uk

I think I've just discovered the real problem!

I have an MQInput terminal, where I have set the MessageDomain to be xml, however when I pass in a valid xml message and look at it in debug immediately after the MQInput node, there is no data there.

I've tried using a standard MQInput terminal with a ResetContent Descriptor to change the domain, but either way I seem to lose the content of the message.

I'm now trawling the manuals for help to see what I'm doing wrong, but the manuals don't seem to give examples, or only talk about files that have an MQRFH2 header. I just have a standard xml file from a third party. A colleague has verified that it is vaild xml for me.

Any ideas?
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Thu Apr 22, 2004 2:57 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

First of all, nothing personal, but don't trust your colleague. It's easy enough to open up an XML file in Internet Explorer or another tool and verify yourself that it's valid XML.

Secondly, which terminal on the MQInput node is getting called? Is the out terminal getting called? If so, then it is valid XML. But you might not see anything in the debugger because the data hasn't been parsed yet.

Try and see what a Trace node right after the MQInput node reports.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Test for existence of a path within an xml message
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.