DTD Question: Attributes vs Elements

Simon St.Laurent simonstl at simonstl.com
Fri Mar 19 20:34:23 GMT 1999


At 02:33 PM 3/19/99 -0500, Kurt Donath wrote:
>
>What is the criteria for selecting when to define data as an attribute
>or element in a DTD?  
>
>Simon says attributes are an "excellent tool for passing along extra
>information about your element to an automated processor - a parser, a
>browser, or a conversion tool.   They are NOT a good place to actually
>store data".  Simon continues, "generally, you should use attributes to
>store information that may not be useful to humans directly but may help
>computers process the element properly."
>
>Would anyone like to add or differ with this?

I'll just clarify a little bit.  In my (highly religious and thoroughly
debatable) viewpoint, attributes are pretty much like annotations.  In a
few cases - empty elements in particular, where the attributes are the only
'real' content - attributes do have a direct impact on the content.
Nonetheless, I'm much happier seeing attributes as a description of the
element - more a metadata role - than providing content.

If you use XML in a display environment that isn't oriented toward
transformation, say CSS, the implications are pretty simple: users will see
the element content directly, if you let them, while the attribute content
is used to generate the presentation, not the content.  From my
perspective, elements contain 'first class' textual content for humans,
while attributes contain information that people will typically access
directly only through an editor.  

In other environments, attributes may seem more or less worthy of storing
content.  From a programmer's perspective, elements and attributes are just
different implementations of about the same thing, and RDF's many syntaxes
make this quite clear. I've definitely softened my strong opinions about
this dichotomy, though I certainly know what style I prefer when I go to
write my own DTDs.


Simon St.Laurent
XML: A Primer
Sharing Bandwidth / Cookies
http://www.simonstl.com

xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1
To (un)subscribe, mailto:majordomo at ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo at ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at ic.ac.uk)




More information about the Xml-dev mailing list