RU beehive logo ITEC dept promo banner
ITEC 325
2018fall
ibarland

DTDs
design thoughts

tags vs. attributes

When specifying a height, which of the following do you like/dislike? Why?

  1.   <wonder height = "37 feet">…</wonder>
    
  2.   <wonder>
        <height>37 feet</height>
        
      </wonder>
    
  3.   <height>
        <measure units="meters">11.8</measure>
        <measure units="feet">37</measure>
      </height>
    
  4.   <height>
        <feet>37</feet>
        <meters>11.8</meters>
      </height>
    
  5.   <height measure="37">
        <units>feet</units>
      </height>
    
  6.   <height>
        <measure>37</measure>
        <units>feet</units>
      </height>
    
  7.   <height units="feet">
        <measure>37</measure>
      </height>
    
  8.   <height>
        37
        <units>feet</units>
      </height>
    
  9.   <height units="feet">
        37
      </height>
    

A common question, when designing an XML language, is when to use a (nested) tag, vs. an attribute on the tag. The rule-of-thumb is “data as tags; metadata as attributes”. For example, in XHTML, the img tag has the filename as an attribute, because the image is the data; the filename is information about how to find the (real) data. A couple of guidelines:

Design practice

Sample exercise:

  1. (a) create a reasonable DTD for census records so that the following file would be legal: dtd-census-example.xml
  2. (b) Critique any strengths and weaknesses of how that file represents information — what changes would you make to represent census records?

Sample exercise: Come up with a DTD for a flow charts, such as imgur.com/ECkYukd#.


logo for creative commons by-attribution license
This page licensed CC-BY 4.0 Ian Barland
Page last generated
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.