These tutorials demonstrate selected features in ASP.NET version 2.0, but they are compatible with later versions of ASP.NET as well. For the current documentation, see the ASP.NET portal on the MSDN Web site.

 

 

   Welcome   |   ASP.NET   |   Web Services   |   Class Browser   
  |   I want my samples in...      

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
View Source

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.