How Do I...Validate XML using the XmlSchemaValidator Class?
This sample illustrates how to validate XML data by using the XmlSchemaValidator class. The
XmlSchemaValidator class is useful in advanced scenarios. It lets you validate an XML infoset
in-place without having to serialize it as an XML document, and then reparse the document by using a validating
XML reader. The sample deserializes XML data by using the XmlSerializer class, and then passes the XML data to
the methods of the XmlSchemaValidator class.
C# XmlSchemaValidator.exe
[This sample can be found at M:\web\users\Sites\AspnetQuickStart\v2.0\QuickStart\howto\samples\Xml\XmlSchemaValidator\
To build this sample, open the SDK command prompt and navigate to the above path. Build the sample using the build tool msbuild
passing the solution file as the first parameter: msbuild mySample.sln. The compiled executable will be found in the sub directory \bin
directory.]
XmlSerializer serializer = new XmlSerializer(typeof(books));
Books myBooks = (books)serializer.Deserialize(reader);
...
XmlSchemaValidator xsv = CreateValidator();
xsv.Initialize();
xsv.ValidateElement("books", "http://www.example.com/my-bookshelf", schemaInfo);
...
C#
Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2005 Microsoft Corporation. All rights reserved.
|