Reminder: <element has-attribute=”something”> stuff </element>

Hmmm … seems rather a lot of my blog entries are going to be along the lines of “look what this other bloke said” … but anyway, look what Ned Batchelder said about elements and attributes:

I say: Use attributes unless you truly need elements. You need elements for a thing if the thing can be repeated, or is itself structured, or has semantics based on its order among its peers.

This was possibly more of a summary than was warranted, but the essential point was fair. I think the bit that got lost in the summary was that in designing schema, by putting something in as an attribute you are constraining things in a way that is obvious (each attribute-type can have at most one value). You can use a schema to constrain something to have only one child of a specific element (I presume), but that’s not obvious! I think being obvious is a good thing, after all, many (most?) schema will be used by people who haven’t thought about the design decisions, and are reacting to them.