Attributes Versus Elements: The Never-ending Choice

2 comments | 1I like it!
December 13, 2001, 12:00 AM —  ITworld — 

Few topics re-occur more frequently, wherever XML developers
congregate, than the attributes versus elements debate. The more
experience you have of developing XML systems, the murkier the waters
surrounding this question. The innocent sounding question can, and
does, spark off debates that touch everything from pragmatism to
epistemology to mereology and back again.

Most developers start out by thinking that having both elements and
attributes is useful and, furthermore, that situations best suited to
one of the other are sort of, well, obvious. This is about the time
that "rules of thumb" force their way into your head such as "if it
appears on the printed page, then it should be an element, otherwise an
attribute"; or, "if it has a fixed number of atomic values, then use an
attribute, otherwise use an element" and so on.

As you get more familiar with XML, the distinction between an element
and an attribute becomes more slippery. Attributes cannot contain
markup and are thus guaranteed to be atomic, whether this is either
good or bad depends on your point of view. Elements are flexible and
hierarchical and can have zero or more textual elements in them. Again,
either good or bad depending on how you look at it.

Somewhere along the line, it occurs to you that attributes and elements
are often interchangeable:


...

Can be written as:


1234
...

For a while perhaps, you start using elements exclusively and only
hoisting content up into attributes if it is required by some specific
program or process. You develop a taste for modern schema languages
that blur the distinction between elements and attributes almost to the
point of disappearance. For example, the RelaxNG schema languages allow
elements and attributes to be used practically interchangeably because
the structure of constraint expressions stays largely the same syntax.
For example:





Is trivially changed to:





Then you start thinking about all the cool stuff you can express in
RelaxNG that cannot be expressed in, say, DTDs and conclude,
conclusively, that attributes are more trouble then they are worth....
Then one day an epistemologist rains on your parade by
pronouncing "attributes are the essence of markup". You see this:


...

Is really syntactic sugar for this:


...

Arrggghhh!

In this model, there is only one tag! -- an UBER-tag with an attribute
called "type" that is used to hold tag names. Most annoyingly, the
scheme works too.

So much for the simple relationship between attributes and elements.
Just think, in some parallel universe the world has been conquered by
HTML. In their HTML version 4.0, a new tag was added in 1998
called "tag". It has an attribute "type" that can hold any name you
like: "invoice", "pullquote", etc.... User groups have hailed this
break through in HTML that allows industry vocabularies to be cleanly
added to the HTML tag set. HTML Supersets such as ebHTML and NewsHTML
are taking that world by storm....

I wonder, do they use entities?

» posted by ITworld staff

ITworld

Sign up for ITworld's Daily newsletter
Follow ITworld on Twitter @IT_world

I like it!
Comments

Huh?

What's the point of posting an article it you cut out bits? This article doesn't make sense because of all the "..." snips.

Useless.

P.S. Forcing TWO captchas? One for the (forced) preview and then again for the actual post. Only 1 is required - I've proved I'm human at that point. And to think you call yourself an IT site. HA!
| reply

replica bags

I'am crazy about replica handbags . I think these replica bags are very attractive .
| reply
peer-to-peer

Esther Schindler
If the comments are ugly, the code is ugly

claird
SVG a graphics format for 21st century

pasmith
Take Chrome OS for a test spin

Sandra Henry-Stocker
Solaris Tip: Have Your Files Changed Since Installation?

sjvn
64-bits of protection?

jfruh
Android fragments vs. the iPhone monolith

mikelgan
What Gizmodo missed about the Pro WX Wireless USB disk drive

 

Sidekick: The Good News & the Bad News
Either way you look at it Microsoft Data Center management did not follow standards or best practices in this failure. In which case it makes me wonder more about the outsourcing of corporate data much less personal data.
- mburton325

Join the conversation here

The Daily Tip

The Daily TipQuick, practical advice for IT pros. Made fresh daily.

Hot tips:

Want to cash in on your IT savvy? Send your tip to tips@itworld.com. If we post it, we'll send you a $25 Amazon e-gift card.

Newsletters

Subscribe to ITWORLD TODAY and receive the latest IT news and analysis.

I would like to receive offers via email from ITworld partners.
By clicking submit you agree to the terms and conditions outlined in ITworld's privacy policy.
Featured Sponsor

AISO founders envisioned a Web hosting company that was environmentally friendly. While the company employed energy-efficient innovations like solar panels, its infrastructure produced unacceptable power and cooling requirements. Find out how AISO leveraged AMD technology to overcome their challenge in this case study white paper.

In this whitepaper, Scalar explores the opportunity to change the landscape with respect to mission critical databases built around Oracle. Leveraging technologies such as Linux, high-end commodity processing power and Oracle RAC technology to architect, design, build and maintain database infrastructure that delivers maximum availability, reliability and performance at a fraction of traditional cost.

On a typical day, weather.com, the Web site for The Weather Channel in Atlanta, serves up between 15 million and 20 million page views. But in September 2004, when back-to-back hurricanes ransacked Florida, the peak traffic on one day more than tripled: over 70 million page views by more than 7 million unique visitors. Read the full success story now.

Marketplace