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 » Mapping empty complex elements

Post new topic  Reply to topic
 Mapping empty complex elements « View previous topic :: View next topic » 
Author Message
gs
PostPosted: Mon May 04, 2009 4:01 am    Post subject: Mapping empty complex elements Reply with quote

Master

Joined: 31 May 2007
Posts: 254
Location: Sweden

Hi,

A flow gets an XML which roughly looks like this:

Code:
<root>
  <header>
    <tag1>text</tag1>
    <tag2>text</tag2>
  </header>
  <body>
    <data>
      <tag1>text</tag1>
      <tag2>text</tag2>
    </data>
  <body>
<root>


The message flows maps to another XML format and is validated before output.
However, we do get messages where the data tag is empty (i.e. <data/>).
This empty tag needs to be preserved to conform with the output message set but the mapping node seems to strip it.

This can, of course, be achieved by using a compute node but is it possible without adding a node?
Shouldn't the mapping node copy the empty element, especially since the target message set specifies it as mandatory?

Am I missing something here?
Thanks


Last edited by gs on Mon May 04, 2009 6:12 am; edited 3 times in total
Back to top
View user's profile Send private message
joebuckeye
PostPosted: Mon May 04, 2009 6:09 am    Post subject: Reply with quote

Partisan

Joined: 24 Aug 2007
Posts: 365
Location: Columbus, OH

Aren't <tag1></tag1> and <tag1/> equivalent? Or am I misreading your question?
Back to top
View user's profile Send private message
gs
PostPosted: Mon May 04, 2009 6:13 am    Post subject: Reply with quote

Master

Joined: 31 May 2007
Posts: 254
Location: Sweden

joebuckeye wrote:
Aren't <tag1></tag1> and <tag1/> equivalent? Or am I misreading your question?


Sorry about that. 3 edits later and things look more a par with reality
Back to top
View user's profile Send private message
joebuckeye
PostPosted: Mon May 04, 2009 6:31 am    Post subject: Reply with quote

Partisan

Joined: 24 Aug 2007
Posts: 365
Location: Columbus, OH

Ok, that makes more sense then.

I can't help though, we had plenty of issues with mapping nodes back in the v5 days and stay away from them now. All of our mappings are done via ESQL now to give us total control over what happens.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Mon May 04, 2009 7:09 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

What are the null handling properties on the message sets?

Are you sure the empty tag is extant in the input message that is passed to the mapping node?
Back to top
View user's profile Send private message
gs
PostPosted: Mon May 04, 2009 8:59 am    Post subject: Reply with quote

Master

Joined: 31 May 2007
Posts: 254
Location: Sweden

mqjeff wrote:
What are the null handling properties on the message sets?


I tried various on the target message set but none of them worked. Also, I'm not sure whether they apply to complex types.
Changing these properties on the source message set shouldn't affect anything, or?

mqjeff wrote:
Are you sure the empty tag is extant in the input message that is passed to the mapping node?


Sure, the XMLNSC parser parses it to an empty string.

I ended up creating a simple compute node which adds the empty element if missing. Ugly but efficient.
Back to top
View user's profile Send private message
gs
PostPosted: Mon May 04, 2009 9:02 am    Post subject: Reply with quote

Master

Joined: 31 May 2007
Posts: 254
Location: Sweden

joebuckeye wrote:
Ok, that makes more sense then.

I can't help though, we had plenty of issues with mapping nodes back in the v5 days and stay away from them now. All of our mappings are done via ESQL now to give us total control over what happens.


That is surely a lot more flexible but gets a bit messy when working with large messages. We do that as well where there are complex conditionals.
Back to top
View user's profile Send private message
kimbert
PostPosted: Tue May 05, 2009 2:04 pm    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

If you are using XMLNSC, then don't bother messing about with the null handling settings. XMLNSC does not use any of the physical format information in a message set.

re: the mapping problem, what exactly are you mapping? A child element of the sometimes-empty tag, or the tag itself? I would be very surprised if it was impossible to do what you require.
Back to top
View user's profile Send private message
gs
PostPosted: Tue May 05, 2009 10:33 pm    Post subject: Reply with quote

Master

Joined: 31 May 2007
Posts: 254
Location: Sweden

kimbert wrote:

re: the mapping problem, what exactly are you mapping? A child element of the sometimes-empty tag, or the tag itself? I would be very surprised if it was impossible to do what you require.


I'm mapping the sometimes empty tag itself. The schema specifies the tag as mandatory but all its children as optional. Strange design? Yes. My design? No
Back to top
View user's profile Send private message
kimbert
PostPosted: Thu May 07, 2009 1:46 am    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

You will need to use an if statement in your map:
Code:
if fn:exists($source/Body/data)
    map $source/Body/data to data
else
    msgmap:empty-element()
Back to top
View user's profile Send private message
gs
PostPosted: Thu May 07, 2009 11:20 pm    Post subject: Reply with quote

Master

Joined: 31 May 2007
Posts: 254
Location: Sweden

kimbert wrote:
You will need to use an if statement in your map:
Code:
if fn:exists($source/Body/data)
    map $source/Body/data to data
else
    msgmap:empty-element()


Thanks but that didn't seem to work.
First of all, exists() only seem to check whether the element is there...which it is, just that it's empty.
Secondly, empty-element() only seems to work for elements of simple type, not complex ones.

I managed to get the conditionals working by using:
Code:
if esql:is-null($source/root/body/data)

to match the empty <data/> tag and not a <data> tag with children.

However, as the empty-element() function doesn't work I have no idea on how to create the empty element in the mapping node.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Fri May 08, 2009 3:14 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Right, so you could check to see if a *child* of $source/Body/data exists or not.
Then you could see what happens if you set a *child* of $source/body/data to null.
Back to top
View user's profile Send private message
gs
PostPosted: Fri May 08, 2009 3:47 am    Post subject: Reply with quote

Master

Joined: 31 May 2007
Posts: 254
Location: Sweden

mqjeff wrote:
Right, so you could check to see if a *child* of $source/Body/data exists or not.
Then you could see what happens if you set a *child* of $source/body/data to null.


AFAIK I can't set fields to null in the mapping editor. For that matter I cannot set complex elements to "" either.
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 » Mapping empty complex elements
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.