Principles of XML design: When to use elements versus attributes by Uche Ogbuji from IBM is probably one of the best resources on the matter.
At the core of the decision is that attributes are 'done' things. You can't change them or modify them or nest them. They are order independent and and distinct within the element (you can't have two of the same thing).
If any of these constraints are things that may change, make the data a child node of the XML.
In your example, you have a person who has a name and an age. I have a first, middle, and last name... and a nickname. And some people have maiden names, multiple middle names, or honorifics - how would you put in John Ronald Reuel Tolkien into such a structure?
And so we have someone who has two middle names that have an order to them. This should clearly show that no, an attribute isn't the best choice for this.
I can't find it currently, but in the above linked document there is a statement that names are things that require a bit of thought leading to "I hope to expand on the treatment of people's names in markup in a future article." If anyone has a lead on this, please leave a comment or edit it into this spot.
On the other hand, the age is something that has a rather fixed structure (I'd suggest the birthday rather than an integer). As such, representing this information in a well known and understood format makes sense in an attribute. A person has one, and only one birthday and there is no 'ordering' to it that you want to preserve.
Uche Ogbuji identifies three core principles in properly designing an xml format. The following are abbreviated quotes from the above linked document.
- Principle of structured information
If the information is expressed in a structured form, especially if the structure may be extensible, use elements. On the other hand: If the information is expressed as an atomic token, use attributes
- Principle of readability
If the information is intended to be read and understood by a person, use elements. If the information is most readily understood and digested by a machine, use attributes.
- Principle of element/attribute binding
Use an element if you need its value to be modified by another attribute
And so, names should elements - they are structured data that is not an atomic token, they are more likely to be read by a human than a computer and they may be modified by another attribute on the name itself.
Dates should be attributes - they are data that is an atomic token, they are more likely the read by a computer than a human (and then transformed into the human's preferred format if need be), and lastly they are unlikely to be modified by other attributes on them.