RE: Prevent empty element from appearing in output

From: Mike Watson (MikeWatson_at_discussions.microsoft.com)
Date: 11/25/04


Date: Thu, 25 Nov 2021 08:41:04 -0800

Hi Phil,

Set the following properties in your XSD.

Address : Min Occurs = 0
Line : Min Occurs = 0/ Max Occurs = * (unbounded)
PostCode : Min Occurs = 0
Country : Min Occurs = 0

In your map :
Add THREE ‘Logical Existences’ to your map and connect the source : ‘Line’,
‘PostCode’ and ‘Country’ to one of the functiods.
Add ONE ‘Logical OR’ functiod to your map. Connect all three outgoing
‘Logical Existences’ functiods to the ONE ‘Logical OR’. Connect the output of
your ‘Logical OR’ to the destination ‘Address’ node.
Now do a straight mapping from
Source ‘Line’ to destination ‘Line’
Source ‘PostCode’ to destination ‘PostCode’
Source ‘Country’ to destination ‘Country’
Generate a sample XML instance from the XSD and remove the ‘Line’,
‘PostCode’ and ‘Country’.
Attach this instance to your map and test it… You should now see that you do
not have the Address node… Then add one ‘Line’ element and test again. You
will see that there is a ‘Line’ node with a parent ‘Address’ node…

I hope that this helps.
Mike Watson

"Phil Knight" wrote:

> In BizTalk 2004, I have an input XML structure as follows -
>
> <Address/>
> <Line>line 1</Line>
> <Line>line 2</Line>
> <Line>line 3</Line>
> <Line>line 4</Line>
> <PostCode>postcode</PostCode>
> <Country>country</Country>
> </Address>
>
>
> I want to map this to an identical structure but with slightly different
> element names in a different schema. However, the Address element should only
> appear in the output if any of the child elements (Line, PostCode and
> Country) are present in the input. Similarly Line, PostCode and Country
> should only appear in the output if present in the input. I can get the last
> bit to work fine by linking each child element to a logical existence
> functoid and a Value Mapping functoid, but when all the fields are empty I am
> still getting an Address element, albeit an empty one, in my output XML. This
> is despite not having any links between the Address element in the input and
> the one in the output, so I can't understand why an empty element should be
> created.
>
> Can anyone give me some pointers on why this is and, more importantly, how
> to prevent the Address element from being output when the corresponding input
> record has no child content?
>
> Regards,
> Phil



Relevant Pages