How Do I...? Common Tasks QuickStart Tutorial
How Do I...Validate an XML Document?
This sample illustrates how to validate an XML document by using a validating XML reader and the
Validate method of the XmlDocument class. A validating XML reader is used to create the XmlDocument object
that contains the XML document to validate. The XmlReaderSettings object used to create the validating XmlReader object
contains the schema used to validate the XML document, and specifies the ValidationEventHandler used to handle
schema validation warnings and errors.
VB XmlDocumentValidation.exe
[This sample can be found at H:\Home\WU_000036_efe47225c86ca62f325a01d8519bc002\Webs\aspnet.sk\quickstarts\QuickStartv20\howto\samples\Xml\XmlDocumentValidation\
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.]
The following code creates the XmlReaderSettings object.
Dim settings As New XmlReaderSettings()
settings.Schemas.Add("urn:xmlns:25hoursaday-com:my-bookshelf", xsd)
AddHandler settings.ValidationEventHandler, AddressOf ValidationCallback
settings.ValidationType = ValidationType.Schema
VB
The following code creates the validating XmlReader object and the XmlDocument object.
Dim doc As New XmlDocument()
doc.Load(XmlReader.Create(document, settings))
VB
The following code validates the changes made to the XML document.
doc.Validate(New ValidationEventHandler(AddressOf ValidationCallback), element.ParentNode)
VB
Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2005 Microsoft Corporation. All rights reserved.
|