Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Project file which will validate for XML with XSD

0.00/5 (No votes)
6 Apr 2004 1  
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:

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