Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions
 Discussion Forums
 HTML, XML, JavaScript...
 Software Reviews
 Editors,Others...
 Top100
 JavaScript Tutorials, ...
 Tutorials
 ASP, CSS, Databases...
 Discussion List
 FAQ, Roundup, Configure ...
 Authoring
 HTML, JavaScript, CSS...
 Design
 Layout, Navigation,...
 Graphics
 Tools, Colors, Images...
 Software
 Browsers, Editors, XML...
 Internet
 Domains, E-Commerce, ...
 WDVL Resources
  Intermdiate, Tutorials,...
 WDVL
 Discussion Lists, Top 100,...
 Technology Jobs


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Top 10 Articles
  1. Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions
  2. JavaScript Tutorial for Programmers
  3. Design
  4. JavaScript Tutorial for Programmers - Objects
  5. JavaScript Tutorial for Programmers - JavaScript Grammar
  6. JavaScript Tutorial for Programmers - Versions of JavaScript
  7. Cascading Style Sheets
  8. JavaScript Tutorial for Programmers - Embedding JavaScript
  9. JavaScript Tutorial for Programmers - Functions
  10. Authoring JavaScript
Domain Name Lookup
Search to find the availability of a domain name. Just enter the complete domain name with extension (.com, .net, .edu)

To E or Not To E: Elements vs. Attributes

April 12, 1999

You may have noticed in the Collection Markup Language example a few seeming inconsistencies such as:

<Published publisher="Harmony Books">1992</Published>

compared with

<Chart>
  <Peak>1</Peak> <!-- US implied -->
  <Peak country="UK">2</Peak>
</Chart>

for the Book and CD parent elements, respectively. Why didn't I make a Publisher element, or why didn't I make peakUS and peakUK attributes, instead of children elements of Chart? Would these have worked?

<Publication>
  <Published>1992</Published>
  <Publisher>Harmony Book</Publisher>
</Publication>

and

<Chart peakUS="1" peakUK="2" />

Believe it or not, while not visually equivalent, they are considered lexically equivalent. Either form would work just fine.

But which is better? Is it best to make almost everything elements, with attributes only used for details? Or is it better to create fewer elements and use attributes liberally? Ah, that is the $64,000 question! In fact, this question has been kicking around the SGML community since at least 1992. The consensus is that there is no one answer that applies to all situations. The decision depends on what you intend to do with the markup. Generally speaking, if my intention with Collection ML is to treat publisher as a relatively unimportant detail (not to be accessed often), whereas if I consider peak chart positions for any country listed to be something I'll want to access frequently, then my original definitions are appropriate. Some of the major differences between elements and attributes are:

  • order of attributes cannot be controlled (element order can be specified in a content model)
  • attributes cannot be hierarchical
  • attributes are more like metadata than content
  • attributes are also useful for enumerated values (name token groups)

For details, examples, and many other opinions, see Robin Cover's page on this subject, SGML/XML: Using Elements and Attributes. There is also a useful set of guidelines by G. Ken Holman posted to the newsgroup comp.xml.text in early 1999.

Writing Our Own ML without a Net: Examples
Doing It With XML, Part 1
Viewing It With IE5, Take 1


Up to => Home / Authoring / Languages / XML / Tutorials / DoingIt




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers