Positional flat files with empty records

by eliasen 29. September 2008 23:01

Hi all

Today i read an email from a guy who had a problem with optional elements in an input giving problems in a positional flat file output. The issue being, of course, that if an element in the input of a map is optional, it might be missing. If the element is missing, it will not be created in the destination of a map, and therefore, the flat file assembler will complain because it needs the element to create the correct positional structure.

I seem to have it working, and will here walk through my solution to explain it.

First of all, I have a Schema for the XML input:

All elements are 1..1 except Element2, which has minOccurs=0.

Secondly, I have a schema for the flat file output:

All elements are mandatory. The record delimiter is 0x0d 0x0a and the two subrecords to the root are positional records.

The map is pretty straight forward:

Just plain connections between the elements.

For testing purposes, I have two test instances, that validate against the input schema. They are exactly the same, except one doesn't have the "Element2"-element in it.

If I try to test the map with the input that has the "Element2"-element, and turn on validation of both input and output, and let the output be "Native", then it will work. If, however, I test the map inside Visual Studio .NET with the example that does not have the Element2 element, it will fail. It will report that:

Output validation error: The element 'FirstElements' has incomplete content. List of possible elements expected: 'Element6'.

So basically, the map does not create the Element6 element in the destination schema, and since the Element6 element is required, it fails validation.

BUT, here comes the surprise; It works if it is deployed. So basically, there must be some inconstency between how the map tester in VS.NET works and how the stuff works when running.

 

I tried changing the schemas to include an element inside the first record as the last element, such that the input has a "SomeElements" record with three elements inside it, of which only the second is optional. Likewise I added a new element in the output schema and updated the map. You can see all three here:

 

Still, I only get errors when testing inside Visual Studio .NET and not when things are deployed and running... Which actually bugs me a bit, but that is a whole other story.

So, to sum up, I only have three explanations as to why it works for me and not for the fellow with the issue:

  1. He is using a BizTalk version that is not BizTalk 2006 R2
  2. He hasn't tried deploying it, and is relying on the map tester
  3. He has some bogus values for the two properties I will mention below

At the end of this post, let me just quickly mention to properties that are available for flat file schemas:

The "Generate Empty Nodes" and "Suppress Empty Nodes" properties might be helpful. They are defined here: http://msdn.microsoft.com/en-us/library/aa559329.aspx

Hope this helps someone.

You can find my project here: FlatFileEmptyElements.zip (27.55 KB)

--
eliasen

Tags:

Comments (3) -

prakash
prakash
12/18/2009 5:37:26 AM #

I am trying to fix exactly opposite problem right now. if my source schema has an empty value then out put (flat file) schema is generating empty node (ex: <val4></val4>). Then after passing through pipeline instead of the delimiter I expect to see, its being replaced by crlf.

ex: if the empty node is val4 then output is as follows.

val1,val2,val3,
  val5,val6 etc....

as you notice delimiter for val4 is missing and crlf is being added. if empty Val4 doesnt exist then everything is fine. Any solution?

Reply

Jan Eliasen
Jan Eliasen
12/19/2009 6:24:14 PM #

Hi

If you get an input with an element thas has an empty input, then the mapper will create the destination element. This is by design.

I am not sure exactly what your issue is. I cannot see from your example if you were expecting val4 to be after val3 in the first line or before val5 in the second line.

If you could provide a test instance of some XML and the desired output, that would help.

Thanks.

Reply

Jan Eliasen
Jan Eliasen
7/14/2010 4:28:48 PM #

Hi all

As a follow up, take a look at blog.eliasen.dk/.../...nAnElementInYourSchema.aspx where I describe that the error message may actually be bogus. Even though the error message states that the output is invalid, the actual error could be that the input is invalid instead.

so be careful out there.

--
eliasen

Reply

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

About the author

Jan Eliasen is 37 years old, divorced and has 2 sons, Andreas (July 2004) and Emil (July 2006).

Jan has a masters degree in computer science and is currently employed at Logica Denmark as an IT architect.

Jan is a 6 times Microsoft MVP in BizTalk Server (not currently an MVP) and proud co-author of the BizTalk 2010 Unleashed book.

BizTalk Server 2010 Unleashed


Buy from Amazon

Microsoft MVP


6 times: July 2004, July 2008, July 2009, July 2010, July 2011, and July 2012. Not currently an MVP.

MCTS

Image to show

Month List

Page List