| |
XML Attributes vs. Elements

Whether you should use attributes or elements in your DTD
depends in large part on the purpose for which you're
designing the document type. The two extremes are best
illustrated with examples.
"Traditional" textual practice is to include the "real"
text (what would be printed) as character data content
and keep the metadata (like line numbers) in attributes,
from where they can more easily be isolated for analysis
or special treatment like display in the margin or in a
mouseover:
<l n="184"><sp>Portia</sp><text>The quality of mercy is not
strain'd,</text></l>
But from a systems point of view, there's nothing wrong
with storing the data the other way around, especially
where the volume of text data on each occasion is
relatively small:
<line speaker="Portia" text="The quality of mercy is not strain'd,">184</line>
Much depends on what you want to do with the information
and which bits of it are most easily accessed by each
method. A good rule of thumb for conventional textual
documents is that if the markup were all stripped away,
the bare text should still be readable and usable, even
if inconvenient.
For database output, however, or other machine-generated
documents, reading might not be meaningful. In this case,
it's certainly possible to have documents where all of
the data is in attributes and the document contains no
character data in content models at all.
|