BizTalk Server General - Prevent empty element from appearing in output

This is Interesting: Free IT Magazines  
Home > Archive > BizTalk Server General > November 2004 > Prevent empty element from appearing in output





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Prevent empty element from appearing in output
Phil Knight

2004-11-25, 5:49 pm

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
Mike Watson

2004-11-25, 5:49 pm

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

Bryan Brouckaert

2004-11-25, 5:49 pm

Hello,

It is reather simple, use a looping functoid between the address records.
Add a (or a combination of) logical functoid and connect the output to the
destination address record. The address will only be created it the logical
functoid returns true.

This behavior is documented in the BizTalk documentation. Look for the
looping funcoid.

Greetings,
Bryan.

"Phil Knight" <PhilKnight@discussions.microsoft.com> schreef in bericht
news:60C1BE51-51EA-4F31-B530-0935B4E14FDE@microsoft.com...
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


Phil Knight

2004-11-29, 7:48 am

Thanks to you both (Mike and Bryan) for the replies. I've cracked it now via
a combination of both your answers. In the end I needed the following:

1. Three logical existence functoids connected to a logical OR, as suggested
by Mike, in order to suppress the Address node in the output when no child
fields are present
2. A looping functoid connecting the Address records, otherwise I was
getting multiple Address elements in the output when I had multiple Line
elements in the input
3. A looping functoid connecting the Line fields, otherwise I only get one
Line element in the output

Not especially intuitive to set up from scratch in my opinion for something
that on the face of it would seem like a fairly simple requirement, and I'd
actually tried most of the above without success before asking for help, but
was missing the looping functoid connecting the Address records (so I kept
getting multiple Address elements in the output). Now it's set up though I
suppose it just about makes sense!

I couldn't actually set the Min Occurs properties on the input xsd as
suggested by Mike by the way since I'm actually parsing a positional flat
file for the input, but adding suppress_empty_nodes to true on the
bschemaInfo element seems to do the trick.

Phil

"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

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com