OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help



   Re: When is an attribute an attribute?

[ Lists Home | Date Index | Thread Index ]
  • From: Jim Amsden <jamsden@us.ibm.com>
  • To: <xml-dev@ic.ac.uk>
  • Date: Mon, 6 Apr 1998 20:50:31 -0400

I think it's best to treat this as an object modeling problem first, and then
an XML representation. The distinction between attribute and content element
then becomes the distinction between an attribute and a containment
relationship with another object. Object attributes are atomic, referentially
transparant characteristics of an object that have no identity of their own.
Generally this corresponds to primitive data types, but this can be somewhat
arbitrary too (e.g., Strings, Date, etc.). Taking a more logical view, an
attribute names some characteristic of an object that models part of its
internal state, and is not considered an object in its own right. That is, no
other objects have relationships to an attribute of an object, but rather to
the object itself.

So if the thing you want to capture has internal structure of its own, or can
be referenced through a link, or can be contained in more than one element,
then its an element, otherwise it's probably an attribute. Note that attributes
have a numer of advantages over content elements:

1. they can have names that indicate the role the value plays in the element.
Element contents have content names, but there is no way to say what role the
content plays in any particular element that contains it.

2. attributes can have default values.

3. attributes have (minimal) data types

4. attributes take up less space as there is no need for an end tag

5. attributes are easier to access in DOM.

There are also some disadvantages:

1. attributes aren't as convenient for large values, or binary entities.

2. values containing quotes can be a bother.

3. attributes can't contain other elements. This isn't really a disadvantage,
but part of what it means to be atomic.

4. white space can't be ignored in an attribute.

My recommendation is to use attributes unless you can't, and certainly use them
to avoid mixed data content in elements whenever possible. The idea is to
encapsulate as much as you can in an individual object but not too much. Use
the principles of data normalization, they work fine here too.

xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/
To (un)subscribe, mailto:majordomo@ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo@ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa@ic.ac.uk)


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS