本文整理汇总了VB.NET中System.Xml.XmlValidatingReader.ValidationEventHandler事件的典型用法代码示例。如果您正苦于以下问题:VB.NET XmlValidatingReader.ValidationEventHandler事件的具体用法?VB.NET XmlValidatingReader.ValidationEventHandler怎么用?VB.NET XmlValidatingReader.ValidationEventHandler使用的例子?那么, 这里精选的事件代码示例或许可以为您提供帮助。
在下文中一共展示了XmlValidatingReader.ValidationEventHandler事件的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Sample
' 导入命名空间
Imports System.IO
Imports System.Xml
Imports System.Xml.Schema
Public Class Sample
Private txtreader As XmlTextReader = Nothing
Private reader As XmlValidatingReader = Nothing
Private m_success As Boolean = True
Public Sub New()
'Validate file against the XSD schema.
'The validation should fail.
Validate("notValidXSD.xml")
End Sub
Public Shared Sub Main()
Dim validation As New Sample()
End Sub
Private Sub Validate(filename As String)
Try
Console.WriteLine("Validating XML file " & filename.ToString())
txtreader = New XmlTextReader(filename)
reader = New XmlValidatingReader(txtreader)
' Set the validation event handler
AddHandler reader.ValidationEventHandler, AddressOf Me.ValidationEventHandle
' Read XML data
While reader.Read()
End While
Console.WriteLine("Validation finished. Validation {0}", IIf(m_success, "successful", "failed"))
Finally
'Close the reader.
If Not (reader Is Nothing) Then
reader.Close()
End If
End Try
End Sub
'Display the validation error.
Private Sub ValidationEventHandle(sender As Object, args As ValidationEventArgs)
m_success = False
Console.WriteLine(ControlChars.CrLf & ControlChars.Tab & "Validation error: " & args.Message)
End Sub
End Class