Modelling with XML

XML modeling languages

XML, like SGML before it, allows you to create your own element names. In the example used earlier we could have used the element <pers> instead of <personName> and <townName> instead of <town>:

 

1
2
3
4
5
<personName>Robert Smith</personName> 
<street>Castle street</street> 
<houseNr>123</houseNr>
<town>Dublin</town>
<telephoneNr>0891232245</telephoneNr>

Therefore, the above example could also look like this:

1
2
3
4
5
<pers>Robert Smith</pers> 
<streetName>Castle street</streetName> 
<house>123</house>
<townName>Dublin</townName>
<telephone>0891232245</telephone>


The XML encoding still successfully describes the encoded data and there are probably many tens of ways of naming these elements. For humans using similar element names may not make a difference because we realise that <pers> or <personName> or <persName> refers to a person's name. However computers typically work on string matching, thus the elements <pers>, <personName> and <persName> represent three different things, as unrelated as <pers> <dog> <fish>.

To help enforce uniformity in element naming and syntax, SGML used a language called  Document Type Definition (DTD). DTDs can also be used with XML. DTDs are a set of rules that specify what elements are used in an SGML/XML document, how frequently they can be used, and what attributes they can contain.

DTDs represent an abstract model of the structure of an XML document, while providing a mechanism for a an individual or community to  develop a vocabulary of element names that suits the data they are encoding. In due course, the W3C, the organisation that monitors and develops HTML and XML standards, developed a rules-based language specifically for XML documents written in XML syntax. While DTDs can still be used with XML, the more powerful and flexible XML Schema and RNG are more commonly used. Later in this course we will introduce you to DTD syntax as it is easier to learn and use than schema languages, while the general principles of modelling are similar.