Rarely do I review XML design without seeing something like:
<spam> <link>http://example.com</link> </spam>
Putting URLs in element content seems to come naturally to people, regardless of the age-old convention from HTML:
<p> <a href="http://example.com"/> </p>
I’ve always disliked this, as I prefer to have URLs and IDs in attributes. I used to think URLs in content was a manifestation of database-refugee XML, but I see it a lot even in carefully-crafted formats.
I was extremely busy and not able to pay much attention during some of the key moments in development of the Atom syntax (RFC 4287), and once I did catch up I was taken aback to find:
<feed> <id>http://example.com</id> ... </feed>
At least Atom does put URLs in href attributes for
link elements, but I find the
id thing annoying in a format so dear to my interest. I do wonder where this tendency comes from.
Conversely, I find that people seem to like putting titles into attributes:
<spam title="The quick brown fox"> Jumps over the lazy dog </spam>
Even though element content is generally a much better place for these. I wonder whether the HTML
a/@title attribute is the influence here (based on the usage, a better name for the HTML construct might have been “hint”, and it’s usually of a very different nature than the constructs people call “titles” in their own vocabularies). FWIW this is one area where Atom gets five stars, with cherries on top (Atom is a superbly well-designed format overall, which makes the
id thing easier to swallow).
For my suggestions on choosing between elements and attributes see “Principles of XML design: When to use elements versus attributes”