当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET XmlValidatingReader.ValidationEventHandler事件代码示例

本文整理汇总了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
开发者ID:VB.NET开发者,项目名称:System.Xml,代码行数:49,代码来源:XmlValidatingReader.ValidationEventHandler


注:本文中的System.Xml.XmlValidatingReader.ValidationEventHandler事件示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。