Content v. attribute

david at megginson.com david at megginson.com
Mon Oct 26 16:49:04 GMT 1998


Dave Winer writes:

 > I consider it a flaw of XML that it has two ways to do hierarchy,
 > one much more powerful than the other. In working with other
 > companies about formats you can get into endless meaningless
 > debates about whether it's better to use attributes or just stick
 > with <tag> structures. When I design XML forms for our own internal
 > applications, I have generally found that if I use attributes, I
 > end up regretting it and switch over to straight tag hierarchy. You
 > always have the option of adding a structure where a scalar used to
 > be when you go that way. With attributes, you're at the end of the
 > road, no way to have structure, so I agree with John Cowan
 > entirely, you never know what's coming down the road, so it's
 > better to leave some room on either side. Dave

There was a long-running debate in the old SGML world about whether
attributes should be allowed at all.  Personally, I like them --
although Len's point about my data being someone else's metadata is
well-received, I still want to have the choice to use

  <section id="foo">
  ...
  </section>

or

  <note security="confidential">Remember to close the panel.</note>

or

  <link href="http://www.megginson.com">Megginson Technologies</link>

rather than

  <section>
  <id>foo</id>
  ...
  </section>

or

  <note>
  <security>confidential</security>
  <text>Remember to close the panel.</text>
  </note>

or

  <link>
  <href>http://www.megginson.com</href>
  <label>Megginson Technologies</label>
  </link>

There are, of course, many cases where the latter examples are
preferable.

I agree with all of the posters that in general using elements rather
than attributes is a good design principle, but I do think that there
are useful data/meta-data distinctions to be made, even if they are
extremely fuzzy.

One of the reasons data people jump to attributes is the fact that

  <account number="345"
	   type="asset"
	   name="Accounts Receivable"
	   currency="usd"
	   status="current"
	   balance="34,569.35"/>

looks an awful lot like

  public interface Account
  {
    public abstract int getNumber ();
    public abstract int getType ();
    public abstract String getName ();
    public abstract String getCurrency ();
    public abstract boolean isCurrent ();
    public abstract float getBalance ();
  }

or

  create table Account (
    num int primary key,
    type int,
    name char(80),
    currency int,
    status bool,
    balance float
  );

It's not easy to start thinking differently.


All the best,


David

-- 
David Megginson                 david at megginson.com
           http://www.megginson.com/

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




More information about the Xml-dev mailing list