• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Elements or Attributes?

The idea of separating elements and attributes in an XML database description is one of the many ways that a distinction can be made between the use of elements and attributes. This question surfaces regularly in SGML circles, and even now it has never really been answered with any degree of conviction. The database example shows one possible answer, but it is only one of many. The following are some things to keep in mind:

  • Elements can be remapped using architectural forms, and attributes can be remapped using XLink; this is, therefore, not a decisive reason for selecting either an element or an attribute.

  • Historically, attributes have been reserved for intangible, abstract properties, such as color and size, and elements are reserved for physical components. To deviate from this usage, especially in an SGML context, may confuse people.

  • It may be easier to edit elements in XML editing tools than attributes, and attribute values may not be so readily displayed as element content. This would favor elements when dealing with human authors.

  • An XML processor is able to check the content of an attribute value more easily than it can check the content of an element. It can't check an attribute value for much, but it can barely check the content of an element at all.

  • The attributes of elements from separate XML documents can be merged quite easily. It can be extremely hard to merge elements, and so, in a distributed environment, attributes may have the edge over elements.

  • In collaborative (multiple) author environments, it is reasonably easy to split XML documents into fragments based on the element structure rather than the attribute values.

  • Sensibly named elements can make (human) authoring easier and less confusing. When selecting an element to contain a list, for example, it's pretty obvious to the human writer that she should choose a list element. However, the selection of the correct attribute (and you will quite often see such cryptic attribute values as ordered and unordered, which come from HTM) can be less than obvious and not very visible. The choice of container elements instead, such as list.numbered and list.bulleted, may make the author's life much simpler.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint