Mega Code Archive

 
Categories / VB.Net / XML
 

XmlSchemaSet contains a cache of XML Schema definition language (XSD) schemas

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.domain.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.domain.com/books"> '  <book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0"> '    <title>C#</title> '    <author> '      <first-name>A</first-name> '      <last-name>B</last-name> '    </author> '    <price>8.99</price> '  </book> '</bookstore> '<?xml version="1.0" encoding="utf-8"?> '<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.domain.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:unsignedShort" use="required" /> '                        <xs:attribute name="ISBN" type="xs:string" use="required" /> '                    </xs:complexType> '                </xs:element> '            </xs:sequence> '        </xs:complexType> '    </xs:element> '</xs:schema>