Click here to Skip to main content
15,395,257 members
Articles / Web Development / ASP.NET
Article
Posted 6 Apr 2004

Stats

59.9K views
476 downloads
17 bookmarked

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
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

Share

About the Author

Anil Gopalakrishnan
Team Leader
India India
No Biography provided

Comments and Discussions

 
Generalgood application and test code Pin
Donsw24-Aug-09 6:59
MemberDonsw24-Aug-09 6:59 
good application and test code, I needed something quick and found yours. this worked and did what I needed. congrats, I did check anothers program which did not work. I gave them a 2, I gave you a 4 for having a working, small, clean code.

cheers,
Donsw
My Recent Article : Backup of Data files - Full and Incremental

GeneralValidating when the XML refuses to refence your XSD Pin
scott.leckie11-Jul-09 15:28
Memberscott.leckie11-Jul-09 15:28 
Generalminoccurs validation Pin
RHBKV21-Nov-07 18:22
MemberRHBKV21-Nov-07 18:22 
GeneralRe: minoccurs validation Pin
Anil Gopalakrishnan22-Nov-07 17:56
MemberAnil Gopalakrishnan22-Nov-07 17:56 
QuestionRe: minoccurs validation Pin
RHBKV27-Nov-07 23:40
MemberRHBKV27-Nov-07 23:40 
GeneralNice app Pin
ceejeeb14-Aug-07 5:15
Memberceejeeb14-Aug-07 5:15 
GeneralRe: Nice app Pin
Anil Gopalakrishnan16-Aug-07 19:55
MemberAnil Gopalakrishnan16-Aug-07 19:55 
GeneralNice little app... Pin
InteractiveLogic22-Jul-04 7:31
MemberInteractiveLogic22-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.