How to Create an XML Dialect - Part 1 - Design and Draft

XML, is a great basis for creating a markup language, it is structured but allows for complete freedom in how everything is arranged, it also allows you to incorporate existing languages using namespaces, but that is for further on in this series.

The first thing you should do is be accustomed to using XML, there are several great tutorials on the net that go about teaching the basic of the markup. Got that? Great we will move on.

Now, you should have an idea about what you want to markup, it could be data about anything cars, planes, books, cutlery, crisps…you get the idea. For this series I am going to be creating a language to markup contact details of friends and family, I am going to call it FFML.

Stage One - Design

The first big step is to get down on paper exactly what data you need to markup, coming up is a list of everything I could think of, but don’t forget we can easily extend this later on if anything else comes up:

  • Name
  • Phone Number(s)
  • Address(s)
  • Birthday
  • Email(s)
  • My relationship to them

Stage Two - Expand

Ok, so we have a basic list, what now? Well first we need to go through our lists and see what can be expanded e.g. Name can become title, first name, middle names and surname. This will help us come up with a tag structure later on.

So after some thought this is the list I came up with:

  • Title
  • First Name
  • Middle Name(s)
  • Surname
  • House Number / House Name
  • Street Address
  • Locality
  • Town / City
  • Country
  • Phone Number
  • Birthday
  • Email(s)
  • Relation

Stage Three - Tags and Attributes

Now as you can see some have been expanded quite a bit while others haven’t been at all. The next step is to think about which of these pieces of data can become elements and which become attributes. For example it would be confusing if the language had two elements for house name and house number it makes more sense to have a house elements and to have a type attribute which will allow name or number to be entered.

Below shows my completed element list with included attributes:

  • <title> - Optional
  • <firstname> -Required
  • <surname>- Required
  • <middlename> - Optional
  • <house type=”name/number”> -Optional
  • <street> - Optional
  • <locality> - Optional
  • <country> - Optional
  • <number type=”house/mobile/work”> - Optional
  • <email type=”personal/school/work/”> - Optional
  • <date type=”birthday/anniversary/other”> - Optional
  • <relation to=”me/friend”> - Optional

Stage Four - Group

To finish of this basic draft the last thing we need to do is create sections in the language, for example, <title>,<firstname>,<surname> and <middlename> can be placed inside a parent <name> tag. Following is an indented list of all the tags and their parents.

  • <name>
    • <title>
    • <firstname>
    • <surname>
    • <middlename>
  • <address>
    • <house>
    • <street>
    • <locality>
    • <postcode>
    • <country>
  • <contact>
    • <phone>
    • <email>
  • <personal>
    • <date>
    • <relation>

Don’t forget that we also need enclosing tags for the language, <ffml></ffml>. And each friend or family member should have their own entry, we will surround each one in a set of <entry> tags. So a basic FFML document might look like this:

<ffml>
      <entry>
           <name>
                   <firstname>Jamie</firstname>
                   <surname>Lewis</surname>
           </name>
      </entry>
      <entry>
           <name>
                   <firstname>John</firstname>
                   <surname>Smith</surname>
           </name>
      </entry>
</ffml>

Stage Five - Rest

And there you have I, our first draft of a language! The best thing you can do now is to put it aside somewhere and to come back to it in just under a weeks time to check it over and potentially spot anything you need to add, or see if you can move some things into another subset.

Next time: We will look at developing a DTD for our language so that it can be validated!

One Response to “How to Create an XML Dialect - Part 1 - Design and Draft”

  1. How to Create an XML Dialect - Part 2 - Document Type Definitions and Schema - Idevs Says:

    [...] 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 [...]

Leave a Reply