Illustrates reading and writing XML schemas from and to a file. : 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.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » XML » XML ValidationScreenshots 
Illustrates reading and writing XML schemas from and to a file.
  


Imports System
Imports System.IO
Imports System.Text
Imports System.Xml
Imports System.Xml.Schema

Class MainClass

    Shared Sub Main()
        Try
            Dim reader As XmlTextReader = New XmlTextReader("example.xsd")
            Dim myschema As XmlSchema = XmlSchema.Read(reader, AddressOf ValidationCallback)
            myschema.Write(Console.Out)

            Dim file As FileStream = New FileStream("new.xsd", FileMode.Create, FileAccess.ReadWrite)
            Dim xwriter As XmlTextWriter = New XmlTextWriter(file, New UTF8Encoding())
            xwriter.Formatting = Formatting.Indented
            myschema.Write(xwriter)
        Catch As Exception
            Console.WriteLine(e)
        End Try
    End Sub

    Shared Sub ValidationCallback(ByVal sender As Object, ByVal args As ValidationEventArgs)
        If args.Severity = XmlSeverityType.Warning Then
            Console.Write("WARNING: "+args.Message)
        Else If args.Severity = XmlSeverityType.Error Then
                Console.Write("ERROR: "+args.Message)
        End If


    End Sub
End Class

'The example takes the example.xsd as input. 
'<?xml version="1.0"?>
'<xs:schema id="test" 
'           targetNamespace="http://tempuri.org/play.xsd" 
'           elementFormDefault="qualified" 
'           xmlns="http://tempuri.org/play.xsd" 
'           xmlns:xs="http://www.w3.org/2001/XMLSchema">
'    <xs:element name='myShoeSize'>
'        <xs:complexType>
'            <xs:simpleContent>
'                <xs:extension base='xs:decimal'>
'                    <xs:attribute name='sizing' type='xs:string' />
'                </xs:extension>
'            </xs:simpleContent>
'        </xs:complexType>
'    </xs:element>
'</xs:schema>

   
    
  
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.Validating Modified xml
6.XmlSchema validation call back
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.