When to use attributes as opposed to elements
Re: When to use attributes as opposed to elements
Author: G. Ken Holman
On Thu, 7 Jan 1999 15:58:56 +1100, "Phill Edwards"
>I must apologise in advance if I use incorrect terminology, but I'm trying
>to understand when to define a piece of information as an attribute of an
>element in ATTLIST rather than as an element.
>On what basis do you decide which is the best way to go?
This is more often a religious question rather than a technical
Lexically, there is little difference between the two, so other
criteria should be used to decide when a value is "best" coded as an
element or as an attribute.
The common reference to discussions of this nature is:
Personally, I follow my own guidelines that have evolved over the
years. These are *never* hard and fast rules, and there are often
exceptions to meet specific situations ... but the first questions I
ask myself (not always in this order) are:
 Does the value have one of an enumeration of values or is the
[1a] - enumerated values can be name token groups in attributes
(see XML productions  and )
- SGML (not XML) also has an attribute type of NUMBER
[1e] - no restrictions on values for the content of elements
 Is the value to be specified, manipulated, organized, consumed by
a program or by a human?
[2a] - I use attributes for computer-manipulated values
[2e] - I use elements for homan-manipulated values
 Does the information represent information *about* content, or is
the information the content itself?
[3a] - I typically put meta-data in attributes
[3e] - I typically put content into elements
 Is the information flat or hierarchical?
[4a] - attributes are flat and a value has no hierarchy
[4e] - elements can be either flat or hierarchical
 Is the information unordered or ordered?
[5a] - multiple attribute values in a single start element have no
[5e] - multiple child elements of an element can be modeled in a
 Is the content to be spell-checked?
[6a] - I put values guaranteed to fail a spell-checker (or
undesired to be spell-checked) in attributes
[6e] - I put values to be spell checked in elements
I hope this helps.
G. Ken Holman gkholman@CraneSoftwrights.com
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/xs/ea/