Create XmlDocument class.
Option Explicit On
Option Strict On
Imports System
Imports System.Xml
Imports System.Xml.Schema
Class XmlDocumentSample
Shared reader As XmlReader
Shared filename As String = "bookdtd.xml"
Public Shared Sub Main()
Dim eventHandler As New ValidationEventHandler(AddressOf XmlDocumentSample.ValidationCallback)
Try
Dim settings As New XmlReaderSettings()
settings.DtdProcessing = DtdProcessing.Parse
settings.ValidationType = ValidationType.DTD
AddHandler settings.ValidationEventHandler, eventHandler
reader = XmlReader.Create(filename, settings)
Dim doc As New XmlDocument()
doc.Load(reader)
Finally
If Not (reader Is Nothing) Then
reader.Close()
End If
End Try
End Sub
Private Shared Sub ValidationCallback(ByVal sender As Object, ByVal args As ValidationEventArgs)
Console.WriteLine("Validation error loading: {0}", filename)
Console.WriteLine(args.Message)
End Sub
End Class
Related examples in the same category