XML technologies / XML / XML in a Nutshell / XML as a document format / Document longevity

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

Computer-oriented XML is often short-lived. A SOAP document representing a request to a .NET Windows server, for example, lasts only while the client sends it and the server reads it into internal structures. Then it is discarded. It lives less than two minutes, let alone two years: fleeting communication, like billions of daily messages normally neither saved nor archived for posterity.

Some applications store more persistent machine data as XML. Gnumeric’s native spreadsheet format, for example, is XML, but only Gnumeric and perhaps other Gnome applications understand it. It serves that program’s needs; exchange with other applications, including future ones, is secondary.

Human-oriented XML, however, is usually longer-lived and independent of software. Encoding the US Declaration of Independence should allow people to read it in 2, 200 or 2,000 years, with any desired tool, including tools not yet invented. This has important implications for both your XML vocabularies and the tools used to read and write them.

First, document the format very well. Provide a thoroughly commented schema and additional written documentation. Prose cannot replace formal schema documentation, but helps readers understand it.

Prefer standard formats such as DocBook and TEI over custom one-off vocabularies. Avoid proprietary schemas owned by a single person or company whose fortunes determine their survival. Even nonprofit consortia such as OASIS or TEI should license schemas generously so intellectual-property restrictions cannot obstruct you. At least one XML vendor has actually sought schema patents. Avoid such applications like the plague. Use freely copyable, redistributable schemas available from many locations.

After choosing a standard, avoid modifying it if possible. Otherwise document every change, adding explanatory comments to schemas and documents. Use the parameter entities built into the DTD to add or remove element types rather than editing DTD files directly.

Conversely, reconstructing the format should be straightforward if schemas and documentation are lost. Always use full element and attribute names. DocBook’s para element is preferable to TEI’s p element. Paragraph would be better still.

Markup alone should identify all inherent structure, without guesswork or whitespace and separators encoding it. Here is an example of what not to do from SVG:

<polygon style="fill: blue; stroke: green; stroke-width: 12" points="350,75 379,161 469,161 397,215 423,301 350,250 277,301 303,215 231,161 321,161" />

The attribute style contains three unrelated entries. Understanding it requires examining the non-XML CSS format. The attribute points is worse: a long numeric list with no indication of what numbers mean, not even which are x or y coordinates. This is preferable:

<polygon fill="blue" stroke="green" stroke-width="12">
  <point x="350" y="75"/>
  <point x="379" y="161"/>
  <point x="469" y="161"/>
  <point x="397" y="215"/>
  <point x="423" y="301"/>
  <point x="350" y="250"/>
  <point x="277" y="301"/>
  <point x="303" y="215"/>
  <point x="231" y="161"/>
  <point x="321" y="161"/>
</polygon>

The attribute-based style syntax is allowed in SVG. But its W3C working group debated coordinate notation heatedly, deciding, wrongly in our view, that the verbose form would never be accepted because of size. Some members thought it better reflected XML’s spirit. We believe size was overrated amid exponentially growing disk capacity and bandwidth, particularly given how easily the second form compresses for transmission or storage.

Stylesheets matter. We know to separate presentation and content and avoid putting font or italic styling into XML. But do not reverse the mistake by putting content into stylesheets. Authors, titles, copyright and other document-specific information belong in documents, even if metadata rather than main content.

Remember that you may be writing for millennia, not months or years. Have some sympathy for the historian deciphering your markup with limited tools.

  

 

 

 

back to top