home—lects—hws
D2L—zoom (snow day)
DTDs
design thoughts
tags vs. attributes
When specifying a height,
which of the following do you like/dislike?
Why?
-
<wonder height = "37 feet">…</wonder>
|
-
<wonder>
<height>37 feet</height>
…
</wonder>
|
-
<height>
<measure units="meters">11.8</measure>
<measure units="feet">37</measure>
</height>
|
-
<height>
<feet>37</feet>
<meters>11.8</meters>
</height>
|
-
<height measure="37">
<units>feet</units>
</height>
|
-
<height>
<measure>37</measure>
<units>feet</units>
</height>
|
-
<height units="feet">
<measure>37</measure>
</height>
|
-
<height>
37
<units>feet</units>
</height>
|
-
<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:
-
Does the additional info itself contain sub-information?
Then you must use a tag element.
Most common case: markup.
For example, if a caption may contain emphasized text, you can't do that with an attribute.
-
Does the info's order matter, relative to its sibling information?
Can there be two such pieces of info?
If so, you must use tag elements.
(Attributes must be unique, and order doesn't matter.)
For example, if a book can have multiple authors (and order matters),
you can't do that with an attribute.
-
Does this represent data, or meta-data (i.e. data about data)?
E.g. the fact that the data 37 is being measured in feet is meta-data.
Put meta-information as attributes, as possible.
-
(Related to the above:)
If the piece of info is a property or modification of an attribute,
then it should be an element.
source
Design practice
Sample exercise:
-
(a) create a reasonable DTD for census records so that the following file would be legal:
dtd-census-example.xml
-
(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#.
home—lects—hws
D2L—zoom (snow day)
This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |
|