Author |
Message
|
gs |
Posted: Mon May 04, 2009 4:01 am Post subject: Mapping empty complex elements |
|
|
 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 |
|
 |
joebuckeye |
Posted: Mon May 04, 2009 6:09 am Post subject: |
|
|
 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 |
|
 |
gs |
Posted: Mon May 04, 2009 6:13 am Post subject: |
|
|
 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 |
|
 |
joebuckeye |
Posted: Mon May 04, 2009 6:31 am Post subject: |
|
|
 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 |
|
 |
mqjeff |
Posted: Mon May 04, 2009 7:09 am Post subject: |
|
|
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 |
|
 |
gs |
Posted: Mon May 04, 2009 8:59 am Post subject: |
|
|
 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 |
|
 |
gs |
Posted: Mon May 04, 2009 9:02 am Post subject: |
|
|
 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 |
|
 |
kimbert |
Posted: Tue May 05, 2009 2:04 pm Post subject: |
|
|
 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 |
|
 |
gs |
Posted: Tue May 05, 2009 10:33 pm Post subject: |
|
|
 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 |
|
 |
kimbert |
Posted: Thu May 07, 2009 1:46 am Post subject: |
|
|
 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 |
|
 |
gs |
Posted: Thu May 07, 2009 11:20 pm Post subject: |
|
|
 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 |
|
 |
mqjeff |
Posted: Fri May 08, 2009 3:14 am Post subject: |
|
|
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 |
|
 |
gs |
Posted: Fri May 08, 2009 3:47 am Post subject: |
|
|
 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 |
|
 |
|