1: Imports System
2: Imports System.Xml
3: Imports System.Xml.Schema
4: Imports System.IO
5:
6: Public Class Sample
7:
8: Public Shared Sub Main()
9:
10: ' Create the XmlSchemaSet class.
11: Dim sc As XmlSchemaSet = New XmlSchemaSet()
12:
13: ' Add the schema to the collection.
14: sc.Add("", "Schema.xsd")
15:
16: ' Set the validation settings.
17: Dim settings As XmlReaderSettings = New XmlReaderSettings()
18: settings.ValidationType = ValidationType.Schema
19: settings.Schemas = sc
20: settings.ValidationFlags = settings.ValidationFlags Or XmlSchemaValidationFlags.ReportValidationWarnings
21: AddHandler settings.ValidationEventHandler, AddressOf ValidationCallBack
22:
23: ' Create the XmlReader object.
24: Dim reader As XmlReader = XmlReader.Create("MyFile.xml", settings)
25:
26: ' Parse the file.
27: While reader.Read()
28: End While
29:
30: Console.ReadKey()
31: End Sub
32:
33: ' Display any validation errors.
34: Private Shared Sub ValidationCallBack(ByVal sender As Object, ByVal e As ValidationEventArgs)
35: Console.WriteLine("Validation Error: {0}", e.Message)
36: End Sub
37: End Class