ARTICLE

XML Schema Validator

Posted by Joe Miguel Articles | Visual Basic 2010 July 01, 2003
The XML Schema Validator checks if a given XML document is well formed and has a valid schema model. If it finds the document is not a valid XML schema, it generates the error telling the problem in the schema.
Download Files:
 
Reader Level:

The XML Schema Validator checks if a given XML document is well formed and has a valid schema model. If it finds the document is not a valid XML schema, it generates the error telling the problem in the schema.

The Browser button lets you browse for an xml document.



The Validate button validates the schema and generates message "Document is valid" if it finds an schema as a valid schema.

If an schema is not a valid schema, it generates to the detailed error listed in the list box.

  

I have used the XmlValidatingReader class. The source code on the Validate button is listed in the following table.

Private Sub validate_Click(ByVal sender As Object, ByVal e As System.EventArgs)
'reset UI information
[error] = ""
result.Text = ""
resultErrors.Text = ""
isValid =
True
header = ""
Try
Dim xml As New XmlTextReader(file.Text)
Dim xsd As New XmlValidatingReader(xml)
'use schemas or DTDs
If documentTypeSchema.Checked = True Then
'schemas - YAAAAAAA
xsd.ValidationType = ValidationType.Schema
Else
If documentTypeNone.Checked = True Then
'so you just want to see if your XML is well formed?
xsd.ValidationType = ValidationType.None
Else
'why do you want to learn this? its old, no one uses it and they are laughing behind your back. Shame on you!
xsd.ValidationType = ValidationType.DTD
End If
End If 'and validation errors events go to...
AddHandler xsd.ValidationEventHandler, AddressOf MyValidationEventHandler
'wait until the read is over, its occuring in a different thread - kinda like when your walking to get a cup of coffee and your mind is in Hawaii
While xsd.Read()
End While
xsd.Close()
' Check whether the document is valid or invalid.
If isValid Then
header = "Document is valid"
Else
header = "Document is invalid"
End If
Catch a As UnauthorizedAccessException
'dont have access permission
[error] = a.Message
Catch a As Exception
'and other things that could go wrong
[error] = a.Message
End Try
resultErrors.Text = [error]
result.Text = header
End Sub 'validate_Click

share this article :
post comment
 

Looks good so far. I need a program to do what you have here. I will make many add-on's. Looks really good!

Posted by David Bush Sep 12, 2011
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Team Foundation Server Hosting
Become a Sponsor