Element or attribute

In a few cases, there is no choice of whether to use an element or an attribute for a given piece of information. For example, if it is a reference to a binary entity, then it must be an attribute value, as the XML standard does not allow such references in element content.

More usually, information could be represented either by a child element or by an attribute. In some cases, either an element or an attribute would be equally well suited to the task, and even professional model designers would argue over some decisions. But in other cases, one or the other would be more suitable, and there are some guidelines that may assist in making this decision.

An element should be chosen if the information:

  • is a sub-division of ...

Get XML Companion, The, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.