Validates XmlDocument against the XML Schema Definition Language (XSD) schemas : XmlDocument « 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 » XML » XmlDocumentScreenshots 
Validates XmlDocument against the XML Schema Definition Language (XSD) schemas
 

Imports System
Imports System.Xml
Imports System.Xml.Schema
Imports System.Xml.XPath

Class XPathValidation
    Shared Sub Main()
            Dim settings As XmlReaderSettings = New XmlReaderSettings()
            settings.Schemas.Add("http://www.domain.com/books""domainBooks.xsd")
            settings.ValidationType = ValidationType.Schema

            Dim reader As XmlReader = XmlReader.Create("domainBooks.xml", settings)
            Dim document As XmlDocument = New XmlDocument()
            document.Load(reader)

            Dim eventHandler As ValidationEventHandler = New ValidationEventHandler(AddressOf ValidationEventHandler)

            document.Validate(eventHandler)

            Dim navigator As XPathNavigator = document.CreateNavigator()
            navigator.MoveToFollowing("price""http://www.domain.com/books")
            Dim writer As XmlWriter = navigator.InsertAfter()
            writer.WriteStartElement("anotherNode""http://www.domain.com/books")
            writer.WriteEndElement()
            writer.Close()

            document.Validate(eventHandler)
    End Sub

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

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

    End Sub

End Class

   
  
Related examples in the same category
1.Create XmlDocument class.
2.XmlDocument.CloneNode
3.XmlDocument.CreateAttribute
4.XmlDocument.CreateCDataSection creates an XmlCDataSection containing the specified data.
5.XmlDocument.CreateComment creates an XmlComment containing the specified data.
6.XmlDocument.CreateDocumentFragment creates an XmlDocumentFragment.
7.XmlDocument.CreateDocumentType returns a new XmlDocumentType object.
8.XmlDocument.CreateElement creates an element with the specified name.
9.XmlDocument.CreateElement creates an element with the specified Prefix, LocalName, and NamespaceURI.
10.XmlDocument.CreateEntityReference creates an XmlEntityReference with the specified name.
11.Saves all the children of the XmlDocument node to the specified XmlWriter.
12.Saves the XmlDocument node to the specified XmlWriter.
13.Gets the XmlDocument to which this node belongs.
14.Set InnerText to a string that includes markup
15.Set InnerXml to a string that includes markup
16.Create a shallow clone.
17.Gets or sets a value indicating whether to preserve white space in element content.
18.InnerXml includes the markup of the element
19.Gets or sets the tag format of the element.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.