VB.Net by API/System.Xml.Serialization/XmlValidatingReader — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 12:51, 26 мая 2010
XmlValidatingReader.Schemas.Add
Imports System.Xml
Imports System.Xml.Schema
Public Class MainClass
Shared Dim valid As Boolean " validation result
Shared Sub Main()
Dim schemas As XmlSchemaCollection " Schemas
valid = True " assume document is valid
schemas = New XmlSchemaCollection()
schemas.Add("book", "book.xdr")
Dim reader As XmlTextReader = New XmlTextReader("document.xml")
Dim validator As XmlValidatingReader = New XmlValidatingReader(reader)
validator.Schemas.Add(schemas)
validator.ValidationType = ValidationType.XDR
AddHandler validator.ValidationEventHandler, AddressOf ValidationError
While validator.Read
End While
If valid Then
Console.WriteLine("Document is valid")
End If
valid = True " reset variable
validator.Close()
End Sub
Shared Private Sub ValidationError(ByVal sender As Object, ByVal arguments As ValidationEventArgs)
Console.WriteLine(arguments.Message)
valid = False
End Sub
End Class
XmlValidatingReader.ValidationEventHandler
Imports System.Xml
Imports System.Xml.Schema
Public Class MainClass
Shared Dim valid As Boolean " validation result
Shared Sub Main()
Dim schemas As XmlSchemaCollection " Schemas
valid = True " assume document is valid
schemas = New XmlSchemaCollection()
schemas.Add("book", "book.xdr")
Dim reader As XmlTextReader = New XmlTextReader("document.xml")
Dim validator As XmlValidatingReader = New XmlValidatingReader(reader)
validator.Schemas.Add(schemas)
validator.ValidationType = ValidationType.XDR
AddHandler validator.ValidationEventHandler, AddressOf ValidationError
While validator.Read
End While
If valid Then
Console.WriteLine("Document is valid")
End If
valid = True " reset variable
validator.Close()
End Sub
Shared Private Sub ValidationError(ByVal sender As Object, ByVal arguments As ValidationEventArgs)
Console.WriteLine(arguments.Message)
valid = False
End Sub
End Class
XmlValidatingReader.ValidationType
Imports System.Xml
Imports System.Xml.Schema
Public Class MainClass
Shared Dim valid As Boolean " validation result
Shared Sub Main()
Dim schemas As XmlSchemaCollection " Schemas
valid = True " assume document is valid
schemas = New XmlSchemaCollection()
schemas.Add("book", "book.xdr")
Dim reader As XmlTextReader = New XmlTextReader("document.xml")
Dim validator As XmlValidatingReader = New XmlValidatingReader(reader)
validator.Schemas.Add(schemas)
validator.ValidationType = ValidationType.XDR
AddHandler validator.ValidationEventHandler, AddressOf ValidationError
While validator.Read
End While
If valid Then
Console.WriteLine("Document is valid")
End If
valid = True " reset variable
validator.Close()
End Sub
Shared Private Sub ValidationError(ByVal sender As Object, ByVal arguments As ValidationEventArgs)
Console.WriteLine(arguments.Message)
valid = False
End Sub
End Class