Validating XML documents against Schemas : XML Schema « XML « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » XML » XML Schema 
25.5.2.Validating XML documents against 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.com/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
25.5.XML Schema
25.5.1.Create XML Schema
25.5.2.Validating XML documents against Schemas
25.5.3.XmlSchema Set Example
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.