Rodrigo Guerreiro

"The purpose of a programming system is to make a computer easy to use", in The Mythical Man-Month
posts - 61, comments - 16, trackbacks - 14

BizTalk Flat file hints - part 2

Following my last post I'm going to describe another hint related to the BizTalk flat files schemas.

Let's use this flat file definition:

Definition Appear how many times Example
Tag: HEA
FileNumber: (length = 4)
1 HEA1234
Tag: ENT
Date: (length = 12)
unbounded ENT200805091416
Tag: DESC
DescID: (length = 3)
Text: (length = 100)
0..1 DESC001This is a test
Tag: VAL
ValueID: (length = 3)
Value: (length = 3)
0..1 VAL001123
Tag: EOF
FileNumber: (length = 4)
1 EOF1234

Under the root node we're going to have 3 main elements: HEA, ENT and EOF. Under the ENT element exists the DESC and VAL elements. But each one may or may not exist independently of one another. But if both of them exist, the order must be DESC->VAL. A first schema definition could be:

image 

Pay attention that the Min Occurs field for the Description and Value elements must be set to 0. Using this example to validate our schema definition, we get an error.

Example Error description

HEA1234
ENT200805091416
DESC001This is a test
VAL001123
ENT200805091416
VAL001123
EOF1234

C:\test2.flat.txt: error BEC2004: Unexpected data found while looking for:
'DESC'
'ENT'
'EOF'
The current definition being parsed is Entry. The stream offset where the error occured is 77. The line number where the error occured is 6. The column where the error occured is 0.

Apparently our schema is well defined. But reading carefully the error message we find out that the error occurred after parsing the second ENT element. The parser is expecting a DESC, ENT or EOF element. But the Description and Value nodes in our schema have the Min Occurs field set to 0.

Once again the solution lies in another magical field of our schema. It's called Parser Optimization and have two possible values: speed and complexity. By default is set to speed. According to this, when the Parser Optimization is set to "complexity mode the flat file parsing engine uses both top-down and bottom-up parsing, and tries to fit data more accurately. In speed mode, the parser tries to fit data as they appear in the stream."

To set the Parser Optimization field click on the <Schema> node and choose the complexity value. It should look like this:

image

Now we're able to get a success return after validating our example file. I hope this could help someone.

Until next time ;)

 

Print | posted on Friday, May 09, 2008 12:46 PM

Powered by: