Martijn's blog - E-Commerce, EAI, BizTalk and .NET


Document contents validation

Lots of customers are asking for a way to validate their document structure based on contents, not merely the structure of the document as BizTalk does by default.

Here's a simple method of achieving document validation within BizTalk Server 2004. Mind you, there is ofcourse a performance trade-off, as BizTalk needs to load the entire message into a DOM tree in order to perform this validation.

First, make sure your schemas actually define your datatypes in a correct manner. It's easy to define the structure and think you're done, but you rarely are. Another hint is to use include schemas, as the actual data definitions are quite frequently re-used, and this promotes definition re-use. An example for a dutch zipcode definition:

<?xml version="1.0" encoding="utf-16"?>
    namespace="" />

            targetNamespace="" />
  <xs:element name="zipcode">
            ref="basetypes:dutch-zipcode" />
followed by the include schema defining:
<?xml version="1.0" encoding="utf-16"?>
  <xs:element name="dutch-zipcode">
      <xs:restriction base="xs:string">
        <xs:pattern value="^[1-9]{1}[0-9]{3} ?[A-Z]{2}$" />

As you can see, the dutch-zipcode has a pattern defined, which is a regular expression comforming to the format of the dutch zipcode. This ensures any zipcode defined within the zipcode element conforms to this specification. However, BizTalk only checks the contents of messages after specifically being instructed to do so, as it pertains a performance trade-off. Telling BizTalk Server 2004 to check the actual contents of inbound messages can easily be achieved by creating a custom pipeline within which you drop an out-of-the-box pipeline component called the XmlValidator:

Ensure you use the design-time property called "Document schemas" to designate our schema as the target for validation.

Deploy the pipeline, configure your ports, drop a correct message into the defined folder and see that it is processed.
Subsequently, drop a message into the folder not adhering to the regular expression defined within the pattern and see BizTalk Server 2004 rejecting the message and setting it's state to "Suspended - Not Resumable" combined with an event in the eventlog telling you why it was denied.

That's all, along with my apologies for being absent for such a long time!


  • Hi,

    Is their a way to log these error in a file for example. Or to do something if an validation error occurs?

    By Anonymous Wouter, at 7:49 PM  

  • Hi Wouter,

    Please see my example of the XmlCompleteValidator component at It performs these validations and logs the errors.

    By Blogger Martijn Hoogendoorn, at 12:57 PM  

Post a Comment

Links to this post:

Create a Link

<< Home