Validating Modified xml : 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 
Validating Modified xml
   

Imports System
Imports System.Xml
Imports System.Xml.Schema
Imports System.Xml.XPath
 
Class ValidatingReaderExample

    Shared Sub Main(ByVal args() As String)

        Try
            Dim settings As XmlReaderSettings = New XmlReaderSettings()
            settings.Schemas.Add("http://www.yourname.com/books""contosoBooks.xsd")
            settings.ValidationType = ValidationType.Schema

            Dim reader As XmlReader = XmlReader.Create("contosoBooks.xml", settings)

            Dim document As XmlDocument = New XmlDocument()
            document.Load(reader)
            Dim navigator As XPathNavigator = document.CreateNavigator()

            Dim validation As ValidationEventHandler = New ValidationEventHandler(AddressOf SchemaValidationHandler)

            navigator.MoveToChild("bookstore""http://www.yourname.com/books")
            navigator.MoveToChild("book""http://www.yourname.com/books")
            navigator.MoveToChild("author""http://www.yourname.com/books")

            navigator.AppendChild("<title>Book Title</title>")

            document.Validate(validation)

            navigator.MoveToParent()
            navigator.MoveToChild("price""http://www.yourname.com/books")
            navigator.SetTypedValue(DateTime.Now)
        Catch As Exception
            Console.WriteLine("ValidatingReaderExample.Exception: {0}", e.Message)
        End Try

    End Sub

    Shared Sub SchemaValidationHandler(ByVal sender As Object, ByVal e As ValidationEventArgs)

        Select Case e.Severity
            Case XmlSeverityType.Error
                Console.WriteLine("Schema Validation Error: {0}", e.Message)
                Exit Sub
            Case XmlSeverityType.Warning
                Console.WriteLine("Schema Validation Warning: {0}", e.Message)
                Exit Sub
        End Select

    End Sub

End Class

   
    
    
  
Related examples in the same category
1.Validate XML document with Validation Error HandlerValidate XML document with Validation Error Handler
2.Console Validator
3.Handle validation event
4.Validate contosoBooks.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_a__va__2s.__co__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.