Sunday, October 19, 2008

Two Ways to Design XML

Brett McLaughlin's article is in substantial disagreement with another article on XML document design.   Brett prefers childless, attribute-only elements as in this example from his article.

<occupation>
    <occupation-type status="part-time"
        job="author" />
  <occupation-type status="part-time"
        job="programmer" />
</occupation>


In the design above, is there a good way to specify the programming language of the programming occupation without also specifying the programming language of the author attribute, probably something we would not want to do?   The better examples of XML design show how to design an XML document so that meaningful metadata can be attributed to document information.

<menu>
  <menu-item>
      <portion unit="mL">250</portion>
      <name>Small soft drink</name>
  </menu-item>
  <menu-item>
      <portion unit="g">500</portion>
      <name>Sirloin steak</name>
  </menu-item>
</menu>

XML design has much in common with relational database design however, hierarchical XML can be much more expressive than a relational design.   The childless, attribute-only design style doesn't reach the level of expressiveness of relational design.