Showing posts with label FlatFileSchema. Show all posts
Showing posts with label FlatFileSchema. Show all posts

Wednesday, 12 June 2013

Create flat File Schema using Flat File schema Wizard and put validation for extra fields



This Article describe you how to create flat File Schema using Flat File schema Wizard.
Consider the Sample:

Id|Name|AddressLine1|AddressLine2|City|State
1|Alice Smith|123 Maple Street|Mill Valley|CA|US
2|Robert Smith|8 Oak Avenue|Old Town|PA|US

Right Click on project -> Add -> New Item -> Flat File schema Wizard.
Name your Schema as InputSchema.xsd.



















Select Your Input Instance File, Name your Root Record.
















Select all portions which are used to define the records.


















Select the option for which records are separated .Since records are separated by {CR}{LF} , then select combo box By delimiter symbol .


















Select {CR}{LF} as child delimiter.



















Define Element, Element Type for Records.
Then Select Delimiter for records (|).



















Define Elements Name and Data Type for each element.
Right Click on Schema -> Validate Instance.
It generates xml like this:


<Input xmlns="http://Biztalk.ProcessDelimiterFlatFile.InputSchema">
<Header xmlns="">
  <Id>Id</Id>
  <Name>Name</Name>
  <AddLine1>AddressLine1</AddLine1>
  <AddLine2>AddressLine2</AddLine2>
  <City>City</City>
  <State>State</State>
  </Header>
 <Details xmlns="">
  <Id>1</Id>
  <Name>Alice Smith</Name>
  <AddLine1>123 Maple Street</AddLine1>
  <AddLine2>Mill Valley</AddLine2>
  <City>CA</City>
  <State>US</State>
  </Details>
<Details xmlns="">
  <Id>1</Id>
  <Name>Robert Smith</Name>
  <AddLine1>8 Oak Avenue</AddLine1>
  <AddLine2>Old Town</AddLine2>
  <City>PA</City>
  <State>US</State>
  </Details>
  </Input>


Now Change Instance file by add one extra field
Id|Name|AddressLine1|AddressLine2|City|State
1|Alice Smith|123 Maple Street|Mill Valley|CA|US|US
1|Robert Smith|8 Oak Avenue|Old Town|PA|US

Then Vaidate instance , it will generate xml like this >





<Input xmlns="http://Biztalk.ProcessDelimiterFlatFile.InputSchema">
<Header xmlns="">
  <Id>Id</Id>
  <Name>Name</Name>
  <AddLine1>AddressLine1</AddLine1>
  <AddLine2>AddressLine2</AddLine2>
  <City>City</City>
  <State>State</State>
  </Header>
<Details xmlns="">
  <Id>1</Id>
  <Name>Alice Smith</Name>
  <AddLine1>123 Maple Street</AddLine1>
  <AddLine2>Mill Valley</AddLine2>
  <City>CA</City>
  <State>US|US</State>
  </Details>
<Details xmlns="">
  <Id>1</Id>
  <Name>Robert Smith</Name>
  <AddLine1>8 Oak Avenue</AddLine1>
  <AddLine2>Old Town</AddLine2>
  <City>PA</City>
  <State>US</State>
  </Details>
  </Input>

So this flat file schema is also validating incorrect flat file, to apply such kind of validation
We need to add Patterns at field level.




















Set Pattern as ^ [^|]*.
Now schema will not validate such instance and give error.

Wednesday, 13 March 2013

Flat File Schema in Biztalk



Flat File Schema:  A flat file schema defines the structure of a class of instance messages that use a flat file format, either delimited or positional or some combination thereof.

Several Legacy system are based on flat files .So conversion of flat files to xml is required in integration projects.

A Flat Files is of several Types:
  • ·         Delimiter,
  • ·         Positional and
  • ·         Combination of both.

Biztalk provides Flat File Schema Wizard for creating flat files Schemas.

In this article we will develop flat file schema for complex file using flat file schema wizard

Example:
INVOICE12345
DestinationPartnerURI:http://www.contoso.com?ID=1E1B9646-48CF-41dd-A0C0-1014B1CE5064
BILLTO,US,John Connor,123 Cedar Street,Mill Valley,CA,90952
101-TT         Plastic flowers   10   4.99      Fragile handle with care
202-RR         Fertilizer        1    10.99     Lawn fertilizer        
453-XS         Weed killer       1    5.99      Lawn weed killer       

In this flatfile there are 4 Type of record

Step 1: Create New Biztalk Project
Step 2: Add New Item, Select Flat File Schema Wizard



















Step 3: Select Instance File.



















Step 4 : Every line in the flat file is delimited by CRLF , hence  Select option  By Delimiter Symbol.


















Step 5: Select Child delimiter as {cr}{lf}.

Step 6: Define Child elements .

·         The Elements type in case of Destination partner and bill to is record because it has more delimiter based fields.
·         The Elements type in case of Item is repeating record because it is repeating several times.
















Step 7: define field properties for each type of record.

Step 8: Destination partner have field with Delimiter (: ) , so select delimiter.















Step 9: BillTo record is based on delimiter (,) , hence select by Delimiter symbol option.














Step 10: now record item is position based, so define the position of each element.











After generating the Schema, right click on schema and validate the instance