Click here to Skip to main content
15,880,503 members
Articles / Web Development / ASP.NET
Article

Project file which will validate for XML with XSD

Rate me:
Please Sign up or sign in to vote.
3.77/5 (11 votes)
6 Apr 2004 61.4K   481   17   8
Validating XML for the given XSD. Output is displayed in a textarea.

Introduction

In this project, you can select your XML file and corresponding XSD file. And you can do a validation.

Error on validation will be shown in the text area below the form. Here is the function which validates the XML:

VB
Private Sub XMLvalidate_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles XMLvalidate.Click
        If Trim(txtXMLname.Text) = "" Or Trim(txtDTDname.Text) = "" Then
            MsgBox("Please select XML/XSD file", MsgBoxStyle.Information)
            Exit Sub
        End If
        Dim tr As XmlTextReader = New XmlTextReader(strXMLFileName)
        Dim sc As XmlSchemaCollection = New XmlSchemaCollection()
        Dim vr As XmlValidatingReader = New XmlValidatingReader(tr)
        Try
            txtMsg.Text = ""
            sc.Add(Nothing, strDTDFileName)
            vr.ValidationType = ValidationType.Schema
            vr.Schemas.Add(sc)
            AddHandler vr.ValidationEventHandler, AddressOf ValidationCallBack
            While (vr.Read())
            End While
            txtMsg.Text = txtMsg.Text & "Validation Success"
            txtMsg.Text = txtMsg.Text & vbCrLf
        Catch ee As Exception
            txtMsg.Text = ee.Message & ":" & ee.Source
        End Try
    End Sub

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Team Leader
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generalgood application and test code Pin
Donsw24-Aug-09 6:59
Donsw24-Aug-09 6:59 
GeneralValidating when the XML refuses to refence your XSD Pin
scott.leckie11-Jul-09 15:28
scott.leckie11-Jul-09 15:28 
Generalminoccurs validation Pin
RHBKV21-Nov-07 18:22
RHBKV21-Nov-07 18:22 
GeneralRe: minoccurs validation Pin
Anil Gopalakrishnan22-Nov-07 17:56
Anil Gopalakrishnan22-Nov-07 17:56 
QuestionRe: minoccurs validation Pin
RHBKV27-Nov-07 23:40
RHBKV27-Nov-07 23:40 
GeneralNice app Pin
ceejeeb14-Aug-07 5:15
ceejeeb14-Aug-07 5:15 
GeneralRe: Nice app Pin
Anil Gopalakrishnan16-Aug-07 19:55
Anil Gopalakrishnan16-Aug-07 19:55 
GeneralNice little app... Pin
InteractiveLogic22-Jul-04 7:31
InteractiveLogic22-Jul-04 7:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.