How to Create an XML Dialect - Part 2 - Document Type Definitions and Schema

Last time we discussed how to design an XML dialect this time I want to focus on how to get the design of your language down in a formal manner.

At the moment there are several ways of formalising the structure of your markup language, I am going to discuss two of them, DTD and Schema. There are others but DTD is the defacto standard and Schema is the W3C’s standard.

DTD

I can do no better than quote w3schools so:

A Document Type Definition defines the legal building blocks of an XML document. It defines the document structure with a list of legal elements and attributes.

It has a very basic structure and has a few drawbacks which we will discuss later, but the main advantage of DTD is that there are several very good validators around to help you check any documents you produce in your language. These validators check your XMLagainst your DTD and help spot any errors, this is very useful and help prevent errors in parsing.

Schema

Schema is supposed to be the standard, but like all standards it hasn’t been widely accepted or used yet, most applications have yet to be updated to include it and I have yet to find a validator for checking documents against it. In any case, it is still a good idea to produce a schema document for your language as schema allows you to go into more detail and so you will have a better, more rounded view of your language.

How do I write a DTD and a Schema?

I can do no better than to refer you to w3school’s DTD Tutorial and their Schema Tutorial. Now that you have your main design you can walk through the tutorials and produce an outline document.

You can then validate your DTD using the W3C’s Validator

Examples

Below are the DTD and Schema documents I produced for FFML.

So there we have it, hopefully by now you should have a design and have a formulised structure. The next step is up to you, you can now do whatever you want with your language, you can use it in applications, style it and put it on the web you can even just leave it and start on another. Please let me know if you have created your own markup language and how it went. Did you do anything differently? I would love to know your own processes.

Leave a Reply