XML technologies / XML Schema / Documenting schemas / Questions of style
(Excerpt from “XML Schema” by Eric van der Vlist)
Writing a schema is almost like writing a program. Two programs may both work, but one may be easier to read and maintain. Readability is good.
The appeal of simplicity
Although W3C XML Schema carefully specifies how processors navigate even the most tangled combinations of its constructs, average readers cannot do the same. I admit quickly getting lost in moderately complex schemas such as the famous schema for schemas.
Enjoy simplicity is a useful rule. Although W3C XML Schema offers many possibilities, every schema need not use them all. Each increases its readability cost.
Programming simplicity rules apply, such as the conflicting brevity rule, split functions longer than a page, and directness rule, functions should be called more than once. Others include keeping code and documentation together, “if you cannot say it in German, you cannot say it in C/C++ (or Java, C#, Perl, Python, etc.) either”, and “do not solve nonexistent problems”.
For XML design, these become: split declarations longer than a page; reference declarations at least once, with exceptions discussed next; keep code and documentation together; if you cannot say it in German, you cannot say it in XML; and do not solve nonexistent problems.
Think globally
When I began using W3C XML Schema, Russian-doll design seemed simplest because it follows instance structure. After writing the reference for W3C XML Schema, I am convinced flat structures with global elements are easier to document and just as easy to write.
Russian-doll design analogizes object-oriented programming and markup. This misleads: XML has no private or local objects unless fragments are encoded or encrypted. Opening the document reveals everything; all is public and needs equal documentation. Name a concept to describe it. W3C XML Schema requires unique names only for global elements. Different content models under one element name, often promoted over DTDs, confuse readers. An element dictionary is the most practical vocabulary reference. Reusing names produces confusing multiple entries, like “place” in an English dictionary. The example of W3C XML Schema, with very different meanings for xs:extension, is instructive. Define elements globally wherever possible. This does not apply to unqualified attributes, which cannot be global.
Show similarities
The third tip conflicts with the first and requires balance. The first two produce flat schemas like our first example in Using and developing schemas, with global elements and attributes and local types. This is readable but hides similarities, such as authors and characters both being people with shared properties. Strong similarities can improve readability when expressed through complex-type derivation or element or attribute groups.
Thus use the capabilities of W3C XML Schema to highlight strong similarities where present.
Copyright © 2003 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “XML Schema” is subject to the same conditions as the bound edition. The work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de