W3C home > Mailing lists > Public > xmlschema-dev@w3.org > August 2009

RE: XML Schema question: A <xs:choice> equivalent for attributes?

From: G. Ken Holman <gkholman@CraneSoftwrights.com>
Date: Fri, 28 Aug 2009 10:58:04 -0300
Message-Id: <7.0.1.0.2.20090828104845.025d6468@wheresmymailserver.com>
To: <xmlschema-dev@w3.org>
At 2009-08-28 15:13 +0200, Simon Cox wrote:
>Else just use elements.
>Why does XML have the choice of element or attribute, anyway ;-)

Of course you can coerce any attribute value into an element, but I 
like having the distinction between containment and attachment.  Thus 
there is no problem distinguishing that which is content of an 
element from that which is about the element as a whole.  When some 
child elements are used to talk about the element as a whole and some 
child elements are used for information contained by the element, 
processing the information may not be different but understanding the 
relationships between information may be very different.

Of course if you want a structured attribute you are obliged to 
coerce that information into a child element (a good example here is 
<xsl:sort>).  So they aren't symmetrical in that regard.

And then not all schema languages treat attributes as first-class 
constructs like elements (RELAX-NG is good in doing so, for example, 
modeling a choice between an element and an attribute, or basing the 
complete structure of an element on different attribute values, or 
from the original post declaring an exclusive choice between 
attributes).  So if you can't use RELAX-NG then there are restrictions.

Robin Cover has collected various opinions about this:

   http://xml.coverpages.org/elementsAndAttrs.html

There is no "correct way of thinking" in this regard .... horses for 
courses ... and I still find some students who shy away completely 
from attributes and think everything should be done as elements.

I think it is an important distinction.

. . . . . . . . . . . . Ken


--
Interested in these classes?  http://www.CraneSoftwrights.com/x/i/
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/x/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman@CraneSoftwrights.com
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/x/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal
Received on Friday, 28 August 2009 13:59:28 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:15:14 GMT