Schema validation component

In my latest project we had a requirement to validate schemas, In several locations within the process flow schemas needed validation.

Now I know validation can be performed in an xml pipeline, but then again when looking in to the pipeline code using reflection validation happens using an XmlReader against the XSD schema, there are several benefits in writing a custom component.

The XmlReader takes in its constructor an XmlReaderSettings component, the XmlReaderSettings exposes an event we can subscribe to which will trigger if the schema validation fails, This allows to create an ESB fault message(we where using the ESB Exception management portal) without running within a try catch block, which is more preferment.

The XmlReaderSettings uses the XmlSchemaSet object to store the schemas it will validate against which allows the ability to cache the schemas and thus improve performance. Note that XmlSchemaSet is guaranteed to be thread safe only when used as a static field(singleton), all schemas that need validation must be loaded in to the XmlSchemaSet in the static constructor and thus create a caching effect.

The code is available here SchemaValidation.cs


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: