This project is read-only.
Project Description
SchematronValidator is a BizTalk Pipeline Component that extends BizTalk's XSD validation capabilities with a Schematron (www.schematron.com) aware component capable of adding assertions over patterns found in XML documents.

Introduction

BizTalk includes out-of-the-box a pipeline component (Microsoft.BizTalk.Component.XMLValidator) that provides common XSD validation functionality to our solutions. This component uses XSD schemas to validate incoming data streams according to the data contract specified therein. Validating your input messages before they are persisted in the messagebox is considered a best practice and this component will complement the BizTalk offering and will be a well behaved member of your toolset in the sense that will log any errors to the local Event Viewer and will suspend the message if any validation errors are found (XSD or Schematron).

What is Schematron

Schematron is described as "A language for making assertions about the presence or absence of patterns in XML documents".
Schematron in a .NET context was first introduced in Improving XML Document Validation with Schematron. The .NET implementation of Schematron can be found at NMatrix (Although a slightly modified version will be included in every release of this project, to provide for a custom XMLResolver - more on this later).
Schematron enables us to define constraints over XML documents that XSD on its own is not able to. Some examples of this constraints are:
  • Validate that two or more elements/attributes have related values (e.g. Sex and Title match - 'Female' and 'Miss' is valid, but 'Female' and 'Mr' is not)
  • Validate one node based on the presence of another
  • etc
As constraints are expressed using XPath statements, one can add any constraint that can be expressed by using one or more XPath statements. This greatly increases the number and type of validation rules one can use.

Schematron vs Other Alternatives

Schematron is not a replacement for, say the Business Rules Engine. Business Rules Engine would be more suitable for (guess what?) define constraints over XML Documents that represent existing business rules, subject to change and managed by the business. Schematron is more appropriate to define constraints that deal with the structure and semantic of XML documents. Schematron respects the principle that validation rules should be close to the data they intend to validate.

Additionally, a call to an external component would carry an aditional performance penalty that should be avoided if possible. This is not equivalent to say that Schematron is more performant that any other solution. As Schematron constraints are specified in XPath statements, it is recommended to performance test your implementations with and without Schematron, to measure the relative performance impact of using this component.

In any case, I believe this component/technique is a valuable addition to your toolset and definitely worth a look.

Your comments would be greatly appreciated.

Last edited Jan 13, 2010 at 12:22 PM by moreirap, version 6