Blogger :
Oleg Tkachenko
All posts :
All posts by Oleg Tkachenko
Category :
.NET XML, System.XML
Blogged date : 2005 Aug 01
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:
- Validation of XML in-place, whithout necessity to reparse it by reading via XmlReader. This is actually how new XmlDocument.Validate() method is implemented.
- Validation of custom XML or even viewed-as-XML data stores
- 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.
- Partial validation
- Access to PSVI (Post Schema Validation Information)
- 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.