VB.Net by API/System.Xml/XmlReaderSettings

Материал из VB Эксперт
Перейти к: навигация, поиск

XmlReaderSettings.Schemas

  
Imports System.Xml
Imports System.Xml.Schema " contains XmlSchemaSet class

Public Class Tester
   Private Shared schemas As XmlSchemaSet " schemas to validate against
   Private Shared valid As Boolean = True " validation result
    Public Shared Sub Main

      schemas = New XmlSchemaSet() " create the XmlSchemaSet class
      schemas.Add("http://www.deitel.ru/booklist", "book.xsd")
      Dim settings As New XmlReaderSettings()
      settings.ValidationType = ValidationType.Schema
      settings.Schemas = schemas
      AddHandler settings.ValidationEventHandler, AddressOf ValidationError
      Dim reader As XmlReader = XmlReader.Create("YourFile.xml", settings)
      While reader.Read()
      End While
      Console.WriteLine(valid)
      valid = True " reset variable
      reader.Close() " close reader stream 
    End Sub
   Private Shared Sub ValidationError(ByVal sender As Object, _
      ByVal arguments As ValidationEventArgs)
      Console.WriteLine(arguments.Message)
      valid = False
   End Sub 
End Class


XmlReaderSettings.ValidationType

  
Imports System.Xml
Imports System.Xml.Schema " contains XmlSchemaSet class

Public Class Tester
   Private Shared schemas As XmlSchemaSet " schemas to validate against
   Private Shared valid As Boolean = True " validation result
    Public Shared Sub Main

      schemas = New XmlSchemaSet() " create the XmlSchemaSet class
      schemas.Add("http://www.deitel.ru/booklist", "book.xsd")
      Dim settings As New XmlReaderSettings()
      settings.ValidationType = ValidationType.Schema
      settings.Schemas = schemas
      AddHandler settings.ValidationEventHandler, AddressOf ValidationError
      Dim reader As XmlReader = XmlReader.Create("YourFile.xml", settings)
      While reader.Read()
      End While
      Console.WriteLine(valid)
      valid = True " reset variable
      reader.Close() " close reader stream 
    End Sub
   Private Shared Sub ValidationError(ByVal sender As Object, _
      ByVal arguments As ValidationEventArgs)
      Console.WriteLine(arguments.Message)
      valid = False
   End Sub 
End Class