New in .NET 2.0: Push-Based XML Validation with XmlSchemaValidator Class

| No Comments | No TrackBacks

This is a real hidden gem in .NET 2.0 everybody (including me) have pretty much overlooked. XmlSchemaValidator class from the System.Xml.Schema namespace is a push-based W3C XML Schema validatation engine. Push-based means different processing model - an opposite for pull-based one. Think about how you work with XmlWriter (push) and XmlReader (pull). With (obsolete now) .NET 1.X's XmlValidatingReader and .NET 2.0's XmlReader with validation enabled you read XML to make sure it's valid. With XmlSchemaValidator you do the opposite - you ask it to validate XML bits using ValidateElement, ValidateAttribute, ValidateText etc methods.

Which scenarios does XmlSchemaValidator enable:

  1. Validation of XML in-place, whithout necessity to reparse it by reading via XmlReader. This is actually how new XmlDocument.Validate() method is implemented.
  2. Validation of custom XML or even viewed-as-XML data stores
  3. Validation during XML construction - now it's possible to create validating XmlWritrer. And I wonder why it's not done yet? That's a job for XML MVPs for sure.
  4. Partial validation
  5. Access to PSVI (Post Schema Validation Information)
  6. Retrieving Expected Particles, Attributes, and Unspecified Default Attributes - this is how XML Editor in Visual Studio 2005 smart Intellisense works.
Quite impressive list and quite impressive class.

Related Blog Posts

No TrackBacks

TrackBack URL:

Leave a comment