Erik Naggum <erik@naggum.net> wrote:
+---------------
| * Boris Schaefer <boris@uncommon-sense.net>
| > Well, I agree that in most cases you will know whether something was
| > an attribute or contents, when you're processing it, but what about:
| > <foo bar="1"><bar>2</bar></foo>
...
| > (foo (bar 1) (bar 2))
| > I don't see how you can distinguish attributes and contents in this case,
| > and how you can translate this back into the same XML. ...
...
| Case in point: An element has a fixed number of attributes. That is
| reflected in a fixed length of the association list that makes up the
| attributes. Attributes are not repetable and not omissible, so if there
| are n attributes in the attribute list for an element, there will be n
| conses with attributes in the cdr of the element representation. There
| are no two ways about this. It is completely and irrevocably unambiguous.
+---------------
While not repeatable, attributes *are* omissible if the DTD for those
attribute contains either default values or the "#IMPLIED" status keyword,
are they not? So if the DTD said:
<!ELEMENT foo (bar | PCDATA)*>
<!ATTLIST foo bar NUMBER #IMPLIED>
that is, the "foo" element has an optional "bar" attribute *and* also
allows an arbitrary number of "bar" sub-elements, then (foo (bar 1) (bar 2))
*would* be ambiguous.
I see two obvious ways to preserve the simplicity you seek:
1. Do what CL does for declarations, that is, reserve a symbol to
tag lists of attributes (like "declare" does), which are optional,
but if present may only appear before all non-attribute subforms:
(foo (attr (bar 1)) (bar 2))
2. Force attribute names and element names into different packages, e.g.:
(foo (attr:bar 1) (bar 2))
or if the current package is never the keyword package, simply:
(foo (:bar 1) (bar 2))
-Rob
p.s. The article "Element/Attribute Distinction Considered Harmful"
<URL:http://www.lists.ic.ac.uk/hypermail/xml-dev/xml-dev-Aug-1999/0375.html>
from the XML-DEV list discusses precisely the same issue, starting with:
After writing the usual 'when to use elements and when to use
attributes' bit for a new book and then spending some time
close up with the XLink specs, I'm really starting to wonder
if we haven't painted ourselves into a corner by treating leaf
elements and attributes differently.
Unfortunately, no significant followups seem to have been posted!!
-----
Rob Warnock, 30-3-510 <rpw3@sgi.com>
SGI Network Engineering <http://reality.sgi.com/rpw3/>
1600 Amphitheatre Pkwy. Phone: 650-933-1673
Mountain View, CA 94043 PP-ASEL-IA