XML technologies / XML / XML in a Nutshell / XML as a document format / Narrative document structures

(Excerpt from “XML in a Nutshell” by Elliotte Rusty Harold & W. Scott Means)

All XML documents are trees. Trees, however, are very general data structures. With a sound education in computer science, and probably even without one, you will know binary trees, red-black trees, balanced trees, B-trees, ordered trees and others. When working with XML, however, a document is highly unlikely to match one of these structures. Instead, XML documents are the most general kind of tree, without particular restrictions on node arrangement or which nodes connect to which others and how. Unlike record-like XML documents, text-oriented documents have little recognizable structure beyond their tree shape.

What does a narrative XML document look like? Of course, there is a root element. Every XML document has one. Generally it represents the document itself. If the document is a book, its root element is book. If it is an article, its root element is article, and so on.

Beyond that, large documents are generally divided into sections of some kind: a book into chapters, an article into parts, or legal documents into claims. These major sections make up most of the document. Sometimes there are different kinds of section, such as one for the table of contents, one for the index, and one for each chapter of a book.

The root element generally also contains elements providing metadata about the document, such as the work’s title, its author, or creation and last modification times. Another common pattern puts metadata in one child of the root and the work’s main content in another. HTML documents follow this pattern. The root element is html. Metadata goes in the head element and the main content in the body element. TEI and DocBook also follow this pattern.

The document’s sections can be divided into subsections, which can themselves be subdivided. The number of hierarchical levels generally depends on document size. An encyclopedia will have many levels of subsections; a flyer probably none. Each section and subsection normally has a title. It may also have elements or attributes identifying metadata about the section, such as its author or last modification date.

Up to this point, mixed content is still avoided. Elements contain child elements and whitespace, and nothing else. Eventually, however, the document’s actual text—the words people should read—must be inserted. In most Western languages, this text will probably be divided into paragraphs and other block elements, such as headings, figures, marginal notes and footnotes. General-purpose document DTDs such as DocBook cannot say more about these entries.

Paragraphs and other block elements mainly contain successive words: text. Some of that text may be marked with inline elements. For example, you might indicate that a particular text string in an element is a date, a person or simply important. Most text, however, is not marked this way.

One point on which XML applications differ is whether block elements may contain further block elements. May a paragraph contain a list, for example? Or a list item a paragraph? More structured documents in which blocks cannot contain other blocks, especially of the same kind, are probably easier to work with. Often, however, there are good reasons to nest blocks. A long list item or quotation, for instance, might contain several paragraphs.

For the most part, this entire structure, from the root to the most deeply nested element, is reasonably linear: words are expected to be read in roughly their document order. If the markup were suddenly removed, leaving only plain text, the result should remain more or less readable. Markup may help index or format the document, but is not a fundamental part of its content.

Another important point about these XML documents is that they are not merely sequences of words; they are composed of words. They contain text for people to read, not numbers, dates or money, unless these occur in the normal narrative flow. The #PCDATA content of elements at the tree’s lowest level mainly has one type: string. If anything has a genuine type beyond string, it is usually metadata about the document—figure number, last modification date and so forth—rather than its actual content.

This explains why DTDs do not provide strong data typing, or any typing at all. The documents for which SGML was designed did not need it. XML documents now perform tasks for which SGML was never intended, such as inventory tracking or census data, and therefore require data types. That is why various people and organizations have invented countless schema languages. Schemas, however, offer no more than DTDs for narrative documents.

Not all XML documents, or even all narrative XML documents, look like those described here. A surprisingly large number of narrative XML applications nevertheless follow this basic pattern, perhaps with a twist here and there. It reflects the basic structure of narrative that has proved itself over the millennia since writing was invented. If you define your own DTDs for general narrative documents, you will probably arrive at something very similar. For more specialized narrative documents, element names should reflect your field—for instance, when writing the next edition of the Scout Handbook, a subsection might be called Ehrenabzeichen —but the basic hierarchy, metadata, sections and subsections, block elements and marked-up text will almost certainly remain the same.

  

 

 

 

back to top