Home > Articles

  • Print
  • + Share This
This chapter is from the book

Flat-File Specifications

Although BizTalk is based on the use of XML message formats internally, and you are strongly encouraged to use XML for the creation of new messages, it also works with flat files. There is such an installed base of legacy flat-file data formats, moreover, that you will likely find yourself dealing with one in your first BizTalk project. Happily, you already learned much of what you need to know to work with flat-file schemas.

Everything we said earlier about creating structure applies to flat files, as does the information regarding record and field node properties. But where data fields in XML messages are known to be delimited with tags and attributes of known syntax, we know little more about delimited and positional files than that they follow certain conventions. For example, consider the following fragment of a comma-delimited message:

C
Sam,,Brown,29
C
Sarah,J,Adams,42
...

This sample constitutes two contact records, each of which consists of a first name, an optional middle initial, a last name, and an age. Each record starts with the literal C followed by a newline character. Each field within the record is delimited by a comma. The comma is inserted between fields, which is called infix notation. Unlike XML, the delimiters are dictated by our schema and there are no tags. Clearly, our BizTalk schemas for delimited files will require some additional information to initialize the parser.

Now consider the positional equivalent to the last message fragment:

Sam     Brown      29
Sarah   JAdams     42

This is actually a hybrid delimited-positional flat file. For clarity, we delimit the records with a new line (the literal record indicator character has been dropped), and each field occupies a fixed area. The first name is allotted 10 characters, the middle initial gets 1, the last name is allowed 15 characters, and the age takes 2 characters. Fields that do not fill the allotted space are left justified and padded with spaces. Everything we've just told you has to be communicated to BizTalk if the flat-file parser is to be able to make sense of an incoming message or compose an outgoing message. Let's take a quick look at the additional properties needed; then we'll go on and create a couple of sample flat-file schemas.

Schema Node Additions

Before diving into the additional properties, we should define three terms. Many of the new properties pertain to delimited format flat files. Delimiters can go in three places with respect to records and fields: before the item it is delimiting, after the item it delimits, and between two items. The last is a special case of the second one; they differ in that when the delimiter follows an item, it always appears, even if no item follows it. In the last case, when the delimiter comes between items, the delimiter will not appear following the last field in a record or after the last record in the message. The terms for these positions are prefix (before), postfix (after), and infix (between).

The Schema node adds the properties found in Table 3.5 to the most commonly used properties listed in Table 3.2. Because this node is a sort of umbrella for everything in the schema, these properties are mostly related to setting defaults for the rest of the schema.

Table 3.5 Commonly Used Flat-File Schema Node Properties

Schema Node Property Name

Meaning and Usage

Default Child Delimiter Type

Configures how the default child delimiter for the schema will be specified in the Default Child Delimiter property. Values are

 

Character—The delimiter is specified as a character string.

 

Hexadecimal—The default delimiter is specified as a hexadecimal value.

 

None—Clears the property in the schema document (default property value).

Default Child Delimiter

Specifies the value of the Default Child Delimiter for the entire schema. This property is not available until the Default Child Delimiter Type property is set. The value of this property may be any string of characters or hexadecimal values, depending on the Child Delimiter Type property.

Default Child Order

Specifies the default delimiter position used throughout the schema. Permissible values are Prefix, Postfix, and Infix.

Default Decimal Character Type

Specifies how the Default Decimal Character property is expressed. Values are Character, Hexadecimal, and None.

Default Decimal Character

Specifies the decimal character (separating integral and fractional values in a numeric value) used as a default. Values are restricted to any of the predefined characters in the drop-down list (international characters), any single character (or hexadecimal value), or blank to remove this property from the schema.

Default Escape Character Type

Configures how the Default Escape Character property is expressed. Permissible values for this property are Character, Hexadecimal, or None to clear this property setting.

Default Escape Character

Specifies the default character used to escape reserved characters so that they may be used as literals in a message. This property may be any of the characters in the drop-down list, any single character, or blank to clear the property setting.

Default Repeating Delimiter Type

Denotes whether the value of the Default Repeating delimiter property is a character string (Character), hexadecimal value string (Hexadecimal), or None to clear this property.

Default Repeating Delimiter

Specifies the character or hexadecimal string used as the default delimiter for repeating fields.

Default Wrap Character Type

Denotes how the value of the Default Wrap Character property is expressed. Values for this property are Character, Hexadecimal, and None.

Default Wrap Character

Specifies, for the entire schema, the default wrap character. This property may take a value from the predefined drop-down list, any single character you provide, or a blank value to clear this property.

Count Positions in Bytes

Indicates whether to count positions within fields in a positional message in bytes. Values are Yes (to count by bytes) or No (to count by character).

Restricted Characters

This property is a collection of character ranges that may not appear in messages specified by this schema.


Record Node Additions

Record nodes also add a number of commonly used properties to those mentioned earlier. Many of these are identical to those listed for the Schema node, except that they establish defaults for the scope of the record rather than the entire document. These properties are Child Delimiter Type, Child Delimiter, Child Order, Escape Character Type, Escape Character, Repeating Delimiter Type, and Repeating Delimiter. In addition, record nodes in flat-file message schemas add the properties found in Table 3.6.

Table 3.6 Commonly Used Properties Unique to Flat-File Records

Record Property Name

Meaning and Usage

Ignore Record Count

When Yes, this record is ignored when records are accumulated. When No, this record is counted for the total. When left blank, the property is cleared.

Preserve Delimiter for Empty Data

Specifies whether delimiters are used when the fields they delimit are empty. By default, BizTalk preserves delimiters for empty fields and suppresses them for empty records. Permissible values are Yes to preserve the delimiter, No to suppress a delimiter, and blank to clear the property. When a record is optional, the delimiter will be suppressed regardless of the value of this property.

Suppress Trailing Delimiters

Indicates whether to suppress the delimiter for trailing records (Yes) or retain them (No). No is the default value.

Tag Identifier

A character string used to identify a tag for the record.

Tag Offset

Specifies the starting position of the record's tag relative to the preceding sibling node or delimiter. This value must be nonzero or blank (default).


Field Node Additions

Schema and record nodes convey the structure of the document but do not give us any data (with the significant but rare exception of mixed-content records). From the point of view of an application, field nodes are the valuable part of the message. In addition to the common properties described for XML message schemas and the obscure, advanced properties in the product documentation), field nodes in flat-file messages also use the properties listed in Table 3.7. Note that in contrast to records, most of these properties are meaningful to positional message formats.

Table 3.7 Commonly Used Field Node Properties Specific to Flat-File Schemas

Field Property Name

Meaning and Usage

Custom Date/Time Format

Specifies a character string indicating the format of date/time fields. The drop-down list provides a number of preconfigured formats, but you can specify a custom format string of your own. Allowable separators are dashes, periods, and slashes. Julian dates may not be specified because of their similarity to nondate numeric types.

Justification

Indicates how data in a positional field is justified when it is shorter than the defined field length. Values are Left and Right.

Minimum Length with Pad Character

Controls how the BizTalk serializer will add pad characters to a positional field to achieve the proper overall length for the field. This property may be set only if Pad Character has been configured.

Pad Character Type

Denotes how the pad character is expressed. Values are Character, Hexadecimal, and (Default). The latter value clears the property in the schema.

Pad Character

Defines a single character that is used by the serializer to pad field values shorter than the space allotted in a positional schema to achieve the proper overall field length. You may select any of the predefined characters in the list box for this property, enter any other single character, or leave the field blank to clear the property in the schema document.

Positional Offset

Specifies the start of the field as an integer offset from the previous sibling or delimiter. Any positive integer less than or equal to the value of Positional Length is acceptable.

Positional Length

Specifies the length of the field starting from the end of the preceding sibling or delimiter. Any positive integer is accepted.


The Positional Offset and Positional Length properties may seem confusing at first. Look at things from the parser and serializer's viewpoint, however. It will see a stream of characters and must do something with them whether you think they are meaningful or not. If there is junk data between one field and the next, perhaps a series of fields you don't want to configure, you want to be able to instruct the parser (and its complementary serializer for outgoing messages) to skip over them and not treat them as part of the next field. Positional Length includes those characters so that the overall message is a series of contiguous fields. Positional Offset tells the parser when to start treating the characters as real data that is a meaningful part of the current field.

Sample Delimited Specification

You should be well-acquainted with the techniques for creating a schema structure by now. But although creating an XML message schema is no trouble at all when you know about specifying structure, a flat-file format requires a bit more. We'll demonstrate the techniques for creating a delimited flat-file in this section. We'll show how to nest records and insert header information.

Suppose that we want to record basic information for a project: namely, the project name, deadline, and team composition. Here's a sample message instance:

Project
Massive Confusion
2004-01-01
Team
Member,Larry Loki,021D
Member,Esther Morris,A234H
Member,Lucretia Borgia,A91R

We start with a header tag, Project, followed by the name and deadline, which is in turn followed by the team composition. The name and deadline constitute a header, and the team has structure of its own. We denote the team record with the tag Team and then list an individual member on each line thereafter. Each member is itself a record composed of the tag Member, followed by the full member name and an employee ID.

As you can see, this message is delimited in several ways. Most of our entries are delimited with a carriage return, but the member information is comma delimited. The tags act to unambiguously indicate what record is appearing at any given time. Consider, for a moment, writing your own parser to handle this message type. You would need to specify tags when there is no convention similar to XML's angle brackets, and you would have to specify different delimiter characters at different points in the message. We're beginning to appreciate what BizTalk offers.

To begin building this schema, add a new Schema item to the project named ProjectDelimited.xsd. Select the Schema node and select the Schema Editor Extensions property. Click the ellipsis and select the Flat File Extension. Note that the value of the Standard property is automatically set to Flat File.

Rename the root node Project and add two child field elements, Name and Deadline. Set the Data Type property for Deadline to xs:date. Next, add a child record to Project and name it Team. Add a child record, Member, to team. Set Min Occurs to 0, and Max Occurs to *. Add child field elements Fullname and EmpID to member. This gives us the structure we need: a root node with two fields, followed by a record composed of a repeating record. All that remains is to set the delimiters and tags. These are given in Table 3.8.

Table 3.8 Tag and Delimiter Properties for the Delimited Schema

Node/Tag Name

Child Delimiter Type

Child Delimiter Character

Child Order

Project

Hexadecimal

0x0A (CR)

Prefix

Team

Hexadecimal

0x0A

Prefix

Member

Character

, (comma)

Prefix


The carriage return delimiters are expressed as hexadecimal because there is no way to express the carriage return as a character. The order of all the delimiters might seem counterintuitive. Most people start out with postfix because they expect their data to be followed by the delimiter. As soon as they see a trailing delimiter, they modify it to be infix. That takes care of the trailing delimiter (which may also be handled with the Suppress Trailing Delimiters property), but puts our first field right after the tag identifier without a delimiter. By preceding our fields with delimiters, we get the message format we desire.

TIP

A couple of common pitfalls might be troubling you if you are following along with the sample. First, if you generate an instance of a flat file, you might be surprised to see an XML document. If this is the case, open the Properties dialog box for the schema and set the Create Instance Output Type to Native. BizTalk likes XML and sometimes needs to be coaxed into seeing things our way. Second, if you are having trouble getting a sample instance to validate because of the record delimiters, you'll find that Visual Studio inserts extra characters. The easiest way to get the single 0x0A carriage return is to open a generated instance in Notepad and edit it, being careful not to change the record delimiters.

Sample Positional Specification

Now let's turn that last schema into a positional message schema. In fact, we'll be making a hybrid delimited-positional schema because that is the form virtually all legacy flat-file formats take when dealing with positional data. As soon as a programmer has to look at the raw data stream, she starts inserting linefeeds for clarity.

This process will be very simple. Perform the following steps:

  1. Copy ProjectDelimited.xsd and rename the copy ProjectPositional.xsd. Add it to the current project.

  2. Select Member and change the Structure property's value to Positional.

  3. Select Fullname and set Justification to Right, Pad Character Type to Hexadecimal, Pad Character to 0x20, and Positional length to 50.

  4. Repeat step 3 with EmpID, but this time make the Positional Length value 10.

Left justification is far more common, but it is easier for us to demonstrate fixed length fields on the page if the actual data appears at the end of the field. Here's what a sample message instance looks like:

Project
More Confusion
2004-06-01
Team
                     Sam . Am    A219
                    Jay Gatsby   Q002
  • + Share This
  • 🔖 Save To Your Account