Modeling with XML
XML: A Markup Language
XML (or eXtensible Markup Language), like SGML before it, defines a set of rules for encoding texts. Unlike a natural language, which consists of identifiable and definable words, XML, on its own, gives you an apparatus for creating "words" or what we in XML lingo call elements.
Let's say you need to encode this person's address:
Samuel Johnson
123 Dictionary Lane
London
United Kingdom
XML does not prescribe element names for you. It simply tells you how to create them. So you could for instance do something like this:
1 2 3 4 |
<name>Samuel Johnson</name> <address>123 Dictionary Lane</address> <city>London</city> <country>United Kingdom</country> |
1 2 3 4 |
<person>Samuel Johnson</person> <street>123 Dictionary Lane</address> <locality>London</locality> <countryName>United Kingdom</countryName> |
<personWhoWasRudeToOldLadies>Samuel Johnson</personWhoWasRudeToOldLadies>. If you don't know the anecdote, ask around.
For humans using various element names may not make a difference because we realize that <name> or <person> and even the outrageous <personWhoWasRudeToOldLadies> all refer to the same thing: the first line of a person's address, containing the name of the person. However computers typically work by matching strings, thus the elements <name>, <person> and <personWhoWasRudeToOldLadies> represent three different things, as unrelated as <somebody>, <dog> and <fish>.
To help enforce uniformity in element naming and syntax, SGML used a language called Document Type Definition (DTD). DTDs are a set of rules that specify what elements are used in an SGML/XML document, how frequently they can be used, at which position in the document hierarchy etc. In the context of dictionaries, a DTD would contain rules that would tell you: an entry must contain a lemma, can contain grammatical information, and can contain one or more senses. A dictionary entry is imaginable without grammatical information, but not without a lemma. Similarly, a dictionary entry can contain one or more senses, but it doesn't have to, because instead of senses, we may encounter a cross-reference.
DTDs represent an abstract model for structuring document, while providing a mechanism for a an individual or community to develop an appropriate vocabulary of element names that suits the data they are encoding. In due course, the W3C, the organization 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 RelaxNG are nowadays more commonly used to constrain the contents of XML documents and to introduce order into the chaos of language.
It is beyond the scope of this course for you to learn how to write your own schemas, but we will be using schemas specifically developed for dictionaries in order to mark up lexicographic data.