[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: When is an attribute an attribute?

  • From: Jim Amsden <jamsden@u...>
  • To: <xml-dev@i...>
  • Date: Mon, 6 Apr 1998 20:50:31 -0400

3 attributes of a turkey.
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@i...
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/
To (un)subscribe, mailto:majordomo@i... the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo@i... the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa@i...)


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.