Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / XML

Simple and Cool XML Validator

2.55/5 (7 votes)
27 Sep 2007CPOL2 min read 1   1K  
A small program you can use to validate an XML document against a schema

Background

I woke up one morning and decided to read about XML. In the video tutorial that I was watching on my computer, the instructor used a self made XML Validator to test the XML and XSD documents he created. I searched the whole DVD-ROM for the Validator, but… it wasn't there. So, I decided to write one that I could use, and also put it up for public use here on The Code Project. Here is the result (it took me half a day to get it to work).

Introduction

This small program will help you validate your XML document/database/... against your laid down specification (schema). The interface is so simple that you'll understand what to do and how to use it once you see it. I didn't do any digging into the source code, because it's mostly Microsoft's code - I only implemented it.

It's very easy to operate the machine; it looks like this:

Screenshot - image001.png

Load the XML schema file by clicking the button next to the XML Schema File textbox; it displays an open file dialog. Browse the folders for your schema file and click open.

In the textbox below, a message appears telling you if your schema file was valid or not. If you had a valid schema file, you might want to validate an XML document against it. The button next to the XML document textbox will open an open file dialog box for you to select your XML document. The moment you load the document, it gets checked if it’s a valid XML document. By this time, the validate button will have been activated. Click this button to validate the XML document against the schema file you specified. If the document conforms to the schema, you'll get a “Document validation against Schema was successful” message. Below is a sample output:

Screenshot - image003.png

The code is rather shabby, but it's easy to understand. If you have a question about the code, please feel free to ask.

History

  • 27th September, 2007: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)