XmlSchema Set Example : 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.3.XmlSchema Set Example
Imports System
Imports System.Xml
Imports System.Xml.Schema

Class XmlSchemaSetExample

    Shared Sub Main()

        Dim booksSettings As XmlReaderSettings = New XmlReaderSettings()
        booksSettings.Schemas.Add("http://www.yourname.com/books""books.xsd")
        booksSettings.ValidationType = ValidationType.Schema
        AddHandler booksSettings.ValidationEventHandler, New ValidationEventHandler(AddressOf booksSettingsValidationEventHandler)

        Dim books As XmlReader = XmlReader.Create("books.xml", booksSettings)

        While books.Read()

        End While

    End Sub

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

        If e.Severity = XmlSeverityType.Warning Then
            Console.Write("WARNING: ")
            Console.WriteLine(e.Message)

        ElseIf e.Severity = XmlSeverityType.Error Then
            Console.Write("ERROR: ")
            Console.WriteLine(e.Message)
        End If

    End Sub

End Class


'<bookstore xmlns="http://www.yourname.com/books">
'  <book genre="autobiography" publicationdate="1999-12-12" ISBN="1-111111-11-1">
'    <title>A</title>
'    <author>
'      <first-name>X</first-name>
'      <last-name>Y</last-name>
'    </author>
'    <price>8.99</price>
'  </book>
'  <book genre="novel" publicationdate="2000-01-01" ISBN="0-201-63361-2">
'    <title>Java</title>
'    <author>
'      <first-name>Q</first-name>
'      <last-name>Q</last-name>
'    </author>
'    <price>11.99</price>
'  </book>
'  <book genre="philosophy" publicationdate="1991-02-15" ISBN="1-861001-57-6">
'    <title>C#</title>
'    <author>
'      <name>Author</name>
'    </author>
'    <price>9.99</price>
'  </book>
'</bookstore>
'
'
'
'The following is the schema that validates the example XML document. 
'
'<?xml version="1.0" encoding="utf-8"?>
'<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.yourname.com/books" xmlns:xs="http://www.w3.org/2001/XMLSchema">
'    <xs:element name="bookstore">
'        <xs:complexType>
'            <xs:sequence>
'                <xs:element maxOccurs="unbounded" name="book">
'                    <xs:complexType>
'                        <xs:sequence>
'                            <xs:element name="title" type="xs:string" />
'                            <xs:element name="author">
'                                <xs:complexType>
'                                    <xs:sequence>
'                                        <xs:element minOccurs="0" name="name" type="xs:string" />
'                                        <xs:element minOccurs="0" name="first-name" type="xs:string" />
'                                        <xs:element minOccurs="0" name="last-name" type="xs:string" />
'                                    </xs:sequence>
'                                </xs:complexType>
'                            </xs:element>
'                            <xs:element name="price" type="xs:decimal" />
'                        </xs:sequence>
'                        <xs:attribute name="genre" type="xs:string" use="required" />
'                        <xs:attribute name="publicationdate" type="xs:date" use="required" />
'                        <xs:attribute name="ISBN" type="xs:string" use="required" />
'                    </xs:complexType>
'                </xs:element>
'            </xs:sequence>
'        </xs:complexType>
'    </xs:element>
'</xs:schema>
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.