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 » Testing for an empty complex element in XML domain

Post new topic  Reply to topic
 Testing for an empty complex element in XML domain « View previous topic :: View next topic » 
Author Message
whydieanut
PostPosted: Mon Nov 04, 2013 4:46 am    Post subject: Testing for an empty complex element in XML domain Reply with quote

Disciple

Joined: 02 Apr 2010
Posts: 186

I need to check the existence of a complex element in a given XML.
The problem is that the code is pretty old and uses the XML domain.
And the way the data is entered, adds new line characters between elements/tags.
Thus using EXISTS(child of field to test) returns true if the element is empty with a new line separating the open and close tags.

Is the only option, to move through all children of <field_to_test> and test if their FIELDNAME isn't empty? Like so:

Code:
IF EXISTS(InRef.parent.field_to_test[]) THEN
  MOVE cursor TO InRef.parent.field_to_test.*[];
  WHILE LASTMOVE(cursor) DO
    IF (FIELDNAME(cursor) <> '') THEN
      SET Flag = 'YES';
      -- Somehow break out of the WHILE loop
    END IF;
  END WHILE;
END IF;



In the below examples, I need to check for the field "<field_to_test>" to be present and have other tags within it (these tags aren't fixed).

What is considered valid is:
Code:

1.
<parent>
  <field_to_test>
    <child1>value1</child1>
    <child2>value2</child2>
  </field_to_test>
  <other_field>value3<other_field>
</parent>


What is considered invalid is:
(The problematic scenario is 1.)
Code:

1.
<parent>
  <field_to_test>
  </field_to_test>
  <other_field>value3<other_field>
</parent>

2.
<parent>
  <field_to_test></field_to_test>
  <other_field>value3<other_field>
</parent>

3.
<parent>
  <field_to_test/>
  <other_field>value3<other_field>
</parent>

4.
<parent>
  <other_field>value3<other_field>
</parent>
Back to top
View user's profile Send private message
Esa
PostPosted: Mon Nov 04, 2013 11:00 am    Post subject: Re: Testing for an empty complex element in XML domain Reply with quote

Grand Master

Joined: 22 May 2008
Posts: 1387
Location: Finland

whydieanut wrote:
I need to check the existence of a complex element in a given XML.
The problem is that the code is pretty old and uses the XML domain.
And the way the data is entered, adds new line characters between elements/tags.
Thus using EXISTS(child of field to test) returns true if the element is empty with a new line separating the open and close tags.

Is the only option, to move through all children of <field_to_test> and test if their FIELDNAME isn't empty?


If you will have to change the code anyway, have you considered migrating to XMLNSC?
Back to top
View user's profile Send private message
kimbert
PostPosted: Mon Nov 04, 2013 12:44 pm    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

You are trying to find out whether the tag contains any child tags. So this should do it:
Code:
IF EXISTS(InRef.parent.field_to_test.(XML.element)*[])) THEN...

You may also need to check for child attributes as well - your examples did not have any tests for that, so maybe the tag does not have any attributes?
_________________
Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Mon Nov 04, 2013 8:26 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

kimbert wrote:
You are trying to find out whether the tag contains any child tags. So this should do it:
Code:
IF EXISTS(InRef.parent.field_to_test.(XML.element)*[])) THEN...

You may also need to check for child attributes as well - your examples did not have any tests for that, so maybe the tag does not have any attributes?

What about checking for child namespace declarations ?
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
dogorsy
PostPosted: Tue Nov 05, 2013 12:26 am    Post subject: Reply with quote

Knight

Joined: 13 Mar 2013
Posts: 553
Location: Home Office

fjb_saper wrote:
kimbert wrote:
You are trying to find out whether the tag contains any child tags. So this should do it:
Code:
IF EXISTS(InRef.parent.field_to_test.(XML.element)*[])) THEN...

You may also need to check for child attributes as well - your examples did not have any tests for that, so maybe the tag does not have any attributes?

What about checking for child namespace declarations ?

Namespaces not supported by the XML parser. Need to use either XMLNS or XMLNSC for that
Back to top
View user's profile Send private message
dogorsy
PostPosted: Tue Nov 05, 2013 12:29 am    Post subject: Reply with quote

Knight

Joined: 13 Mar 2013
Posts: 553
Location: Home Office

kimbert wrote:
You are trying to find out whether the tag contains any child tags. So this should do it:
Code:
IF EXISTS(InRef.parent.field_to_test.(XML.element)*[])) THEN...

You may also need to check for child attributes as well - your examples did not have any tests for that, so maybe the tag does not have any attributes?

:
Code:
IF EXISTS(InRef.parent.field_to_test.*[])) THEN...

will detect child attributes as well.
Back to top
View user's profile Send private message
whydieanut
PostPosted: Tue Nov 05, 2013 12:52 am    Post subject: Reply with quote

Disciple

Joined: 02 Apr 2010
Posts: 186

Quote:
If you will have to change the code anyway, have you considered migrating to XMLNSC?

We are using XMLNSC for any new developments, but moving existing code to XMLNSC has too much dependency/regression testing needed, that the team can't afford at the moment. So we have to work with XML.
I know it's less than ideal, but that's how it is, for now.

Quote:
What about checking for child namespace declarations ?

No namespaces are being used.



Quote:
You are trying to find out whether the tag contains any child tags. So this should do it:
Code:
IF EXISTS(InRef.parent.field_to_test.(XML.element)*[])) THEN...

You may also need to check for child attributes as well - your examples did not have any tests for that, so maybe the tag does not have any attributes?

The field_to_test may or may not have attributes, am not very sure. Will need to check if it does, and also if the existence of attribute is a positive case or not.

Now, assuming there are no attributes, I need to test for the existence of the <field_to_test> itself AND any child TAGS (and not text nodes because of the \n).
So specifying XML.Element will suffice, meaning it'll leave out any text nodes (caused by \n)?

Don't have access to a system to test it right now, hence asking here itself
Back to top
View user's profile Send private message
dogorsy
PostPosted: Tue Nov 05, 2013 12:54 am    Post subject: Reply with quote

Knight

Joined: 13 Mar 2013
Posts: 553
Location: Home Office

as said above
Code:
IF EXISTS(InRef.parent.field_to_test.*[])) THEN...

is what you need.
Back to top
View user's profile Send private message
whydieanut
PostPosted: Tue Nov 05, 2013 2:33 am    Post subject: Reply with quote

Disciple

Joined: 02 Apr 2010
Posts: 186

This returns true even for non element text nodes (like \n)

Will test if XML.Element solves this.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Testing for an empty complex element in XML domain
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.