WWW Yariv Hammer's Code Site

Friday, December 16, 2005

Xml Schema Reader Application

Download from here (~200 KB)

There are several ways to handle Xmls in .NET . My favourite is DataSet.ReadXml method. It is fast, clean, efficient and productive.
Xml files are not that different from databases, although their use is somewhat different. The use of DataSet helps us as developers to use one API (which is ADO.NET) in order to handle both relational data when it is brought from the database or when it is brought from Xml files.

In order to read Xmls into Typed Datasets, or to make them valid, we should use Xml Schemas (xsd files). Now, designing Xml Schemas is a whole new ballgame. We can use the designer of VS.NET to help us, but I personally find it very awkward. Most of the time I know how my Xml file should look. I just don't know how the Schema file should look, and coding (or designing) it is a real pain. I also don't know how the DataSet will look when I import my Xml. Which elements are tables, which are fields, and so on. Sometimes DataRelations will be created for me by the ReadXml method, and primary keys too.

One more case which I find difficult, is when I get an already prepared xsd file, and it can be big. The person who designed the xsd may not even have an Xml file example for me. So it can be very difficult to work with it (I will need few hours spent to investigate the schema).

So here comes XmlSchemaReader for our aid.

The Application
XmlSchemaReader is a simple tool, written in C# by me, which is designed to address these issues. You simply load the Xml or Xsd file (by clicking on xml or xsd button, and then selecting it from the Open Dialog). The application will tell you if it is illegal to read it into a DataSet.

After the file is loaded the DataTables are seen in the ListBox in the left. When the selecting a table, the data is seen in the grid in Data tab. The data can be edited and then saved by pressing the Save button (be careful - it will be saved into the file specified in the TextBox). A neat feature is to attach the schema into an Xml file with data (By clicking Save Schema). So I can write my xml first (outside, in notepad for example), and then generate the schema later.

Two more tabs are Column and Relations. The Columns tab will show you the generated columns for each table, the datatype, and if it is a primary key (+ or -). Last, the Relations tab will show you the generated relations from the Xml.

Best Practice
I suggest you follow these steps:
1. Write the xml in Notepad, as you think it should look.
2. Load the xml to the XmlSchemaReader application.
3. Look at the tables and columns. Add data if you wish and save. I suggest you create a backup before saving.
4. Save the schema into a seperate file, or into the xml file.
5. Edit the schema outside the XmlSchemaReader application. For example, change types of columns.
6. Whenever you need a view, load the file into the application.

It really saved me a lot of time!!!

Last Words
I am giving the XmlSchemaReader for free, without any profit on my part. Please do not distribute it, or use it in production versions. Please use it only for your own use. Read the License file before using it. Feel free to advertise me of course ;)

Obviousely improvements can be made to the interface and capabilities. I will probably get there, but the tool is really helpful even as it is. You may post comments on any failures, bugs, or suggestions you have.


Post a Comment

<< Home

Feel free to use everything here. Add links to my site if you wish.

Do not copy anything to other sites without adding link to here.

All the contents of the site belong to Yariv Hammer.