Wednesday, July 7, 2010

XML Schema Design Links

Here are my definite sources for XML Schema Design:

Zero, One, or Many Namespaces?
W3C XML Schema: DOs and DON'Ts (Kohsuke)
Reference Model For XML Design (PDF)
W3C XML Schema Design Patterns: Avoiding Complexity (Obasanjo)

These all represent slightly different viewpoints.

For example, these are Obasanjo's guidelines altered from Kohsuke's:

I've altered some of Kohsuke's original guidelines:
  • Do use element declarations, attribute groups, model groups, and simple types.
  • Do use XML namespaces as much as possible. Learn the correct way to use them.
  • Do not try to be a master of XML Schema. It would take months.
  • Do not use complex types and attribute declarations.
  • Do not use notations
  • Do not use local declarations.
  • Do not carefully use substitution groups.
  • Do not carefully use a schema without the targetNamespace attribute (aka chameleon schema.)
I propose some additional guidelines as well:
  • Do favor key/keyref/unique over ID/IDREF for identity constraints.
  • Do not use default or fixed values especially for types of xs:QName.
  • Do not use type or group redefinition.
  • Do use restriction and extension of simple types.
  • Do use extension of complex types.
  • Do carefully use restriction of complex types.
  • Do carefully use abstract types.
  • Do use elementFormDefault set to qualified and attributeFormDefault set to unqualified.
  • Do use wildcards to provide well defined points of extensibility.
There are still some problems with extensions of complex types and validation. The problem is the need to have xsi:type attributes sprinkled in your XML documents. From a purist point of view, we should not really have validation artifacts in our XML tags.

No comments: