Home > Articles > Programming > Windows Programming

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

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020