本文整理汇总了VB.NET中System.Xml.XmlValidatingReader.ValidationType属性的典型用法代码示例。如果您正苦于以下问题:VB.NET XmlValidatingReader.ValidationType属性的具体用法?VB.NET XmlValidatingReader.ValidationType怎么用?VB.NET XmlValidatingReader.ValidationType使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。
在下文中一共展示了XmlValidatingReader.ValidationType属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: Sample
' 导入命名空间
Imports System.IO
Imports System.Xml
Imports System.Xml.Schema
Public Class Sample
Private doc1 As String = "notValid.xml"
Private doc2 As String = "cdDTD.xml"
Private doc3 As String = "book1.xml"
Private txtreader As XmlTextReader = Nothing
Private reader As XmlValidatingReader = Nothing
Private m_success As Boolean = True
Public Sub New()
'Parse the files and validate when requested.
Validate(doc1, ValidationType.XDR) 'Validation should fail.
Validate(doc2, ValidationType.DTD) 'Validation should fail.
Validate(doc3, ValidationType.None) 'No validation performed.
End Sub
Public Shared Sub Main()
Dim validation As New Sample()
End Sub
Private Sub Validate(filename As String, vt As ValidationType)
Try
'Implement the readers. Set the ValidationType.
txtreader = New XmlTextReader(filename)
reader = New XmlValidatingReader(txtreader)
reader.ValidationType = vt
'If the reader is set to validate, set the event handler.
If vt = ValidationType.None Then
Console.WriteLine(ControlChars.Cr & "Parsing XML file " & filename.ToString())
Else
Console.WriteLine(ControlChars.Cr & "Validating XML file " & filename.ToString())
m_success = True
'Set the validation event handler.
AddHandler reader.ValidationEventHandler, AddressOf ValidationCallBack
End If
' Read XML data
While reader.Read()
End While
If vt = ValidationType.None Then
Console.WriteLine("Finished parsing file.")
Else
Console.WriteLine("Validation finished. Validation {0}", IIf(m_success, "successful", "failed"))
End If
Finally
'Close the reader.
If Not (reader Is Nothing) Then
reader.Close()
End If
End Try
End Sub
'Display the validation errors.
Private Sub ValidationCallBack(sender As Object, args As ValidationEventArgs)
m_success = False
Console.Write(ControlChars.CrLf & ControlChars.Tab & "Validation error: " & args.Message)
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System.Xml,代码行数:66,代码来源:XmlValidatingReader.ValidationType
注:本文中的System.Xml.XmlValidatingReader.ValidationType属性示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论