[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: XML attributes (was: Re: CVS update: ....)

From: Greg Hudson <ghudson_at_MIT.EDU>
Date: 2000-10-24 08:41:35 CEST

> at some point, I'm probably going to start a gentle push to *not*
> use XML attributes at all.

(Another reason I don't like XML for application protocols: attributes
do not enhance XML's expressibility and it is is ambiguous when it is
appropriate to use them. Sorry I harp so much on this.)

There seems to be a rapidly-becoming-old debate in the XML community
between "element-normal" and "attribute-normal" forms for data, and
various compromises in between. In the element-normal form,
attributes are never used, and string data is conveyed in the pcdata
of elements. In the attribute-normal form, pcdata is never used
(although compromises are likely to be made for large objects), and
string data is conveyed in the values of attributes. Our XML delta
format is attribute-normal except for text deltas and the values of
properties. The issues I know of on either side are:

        * XML is stupidly verbose for elements (especially elements
          with longish names), but not for attributes. So attributes
          tend to soften the blow of XML's verbosity.

        * In most implementations, attribute values are presented to
          the application all at once along with the element name. If
          the same values are present in the pcdata of sub-elements,
          the application has to go to more steps to gather that data
          together.

        * If you have a DTD, attribute values can be restricted in
          certain ways (such as "must be a unique identifier" or "must
          refer to an identifier used elsewhere in the document") and
          those restrictions can be enforced by a validating parser
          instead of by the application.

        * Similarly, if you have a DTD and a validating parser, the
          DTD can do some work for the application; it can match up
          IDREFs with IDs and can fill in default values when the
          DTD specifies them.

        * A sub-element can be extended to include further structure;
          an attribute cannot be so extended, although new attributes
          can of course be added alongside for some simple kinds of
          extensions.

        * You have to use elements no matter what, but nothing forces
          you to use attributes, so element-normal form uses fewer of
          XML's mechanisms. This is arguably more elegant and
          simpler, although in practice, having to collect all the
          pcdata together is more annoying than having to learn how
          your XML implementation deals with attributes.

Note that not everyone in the XML community believes in DTDs and
validating parsers as valuble things, so not all of the advantages I
listed for attributes carry weight with everyone. In particular, we
don't use a validating parser, so DTDs don't help us except as a form
of documentation for people, or conceivably as a debugging aid.

I don't have a particular opinion on the matter, just a lot of things
to say.
Received on Sat Oct 21 14:36:12 2006

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.