Validate XML document with Validation Error Handler : XML Validation « XML « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Date Time
8.Development
9.Event
10.File Directory
11.Generics
12.GUI
13.Internationalization I18N
14.Language Basics
15.LINQ
16.Network Remote
17.Reflection
18.Security
19.Thread
20.Windows Presentation Foundation
21.Windows System
22.XML
23.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » XML » XML ValidationScreenshots 
Validate XML document with Validation Error Handler
Validate XML document with Validation Error Handler
   
Imports System
Imports System.Xml
Imports System.Xml.Schema
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Collections
Imports System.Data
Imports System.Windows.Forms


Public Class MainClass
    
    Shared Sub Main()
        Dim xtr As New XmlTextReader("book.xml")
        Dim xvr As New XmlValidatingReader(xtr)

        xvr.ValidationType = ValidationType.Schema
        AddHandler xvr.ValidationEventHandler, _
                   New ValidationEventHandler(AddressOf ValidationErrorHandler)

        While xvr.Read()
            If TypeOf xvr.SchemaType Is XmlSchemaComplexType Then
                Console.WriteLine("{0} - {1}", xvr.NodeType, xvr.Name)
                While xvr.MoveToNextAttribute()
                    Console.WriteLine("  {0} - {1}: {2}", _
                                        xvr.NodeType, xvr.Name, xvr.Value)
                End While
            End If
        End While
    End Sub

    Shared Sub ValidationErrorHandler(ByVal sender As Object, _
                               ByVal args As ValidationEventArgs)
        Console.WriteLine("XML Document Validation Failure")
        Console.WriteLine()
        Console.WriteLine("The ValidatingReader Failed with severity : {0}", _
                                                                args.Severity)
        Console.WriteLine("The failure message was: {0}", args.Message)
    End Sub
End Class


'<?xml version = "1.0"?>

'<books xmlns = "x-schema:book.xdr">
'   <book>
'      <title>C# How to Program</title>
'   </book>

'   <book>
'      <title>Java How to Program, 4/e</title>
'   </book>

'   <book>
'      <title>Visual Basic .NET How to Program</title>
'   </book>

'   <book>
'      <title>Advanced Java Platform How to Program</title>
'   </book>

'   <book>
'      <title>Python How to Program</title>
'   </book>
'</books>



           
         
    
    
  
Related examples in the same category
1.Console Validator
2.Handle validation event
3.Validate contosoBooks.xml
4.Validating Modified xml
5.Illustrates reading and writing XML schemas from and to a file.
6.XmlSchema validation call back
7.AddressOf ValidationCallbackOne
w__w_w._j__av__a__2_s__._c___o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.