Category Archives: Wire format

Attributes versus elements in FHIR Xml

Some of you have asked me why, since our latest (0.7) Fhir Xml format, we use attributes to contain most of the “primitive” values, instead of the somewhat more common elements. E.g. for birthdate we now use:

<birthDate value="1972-11-30"/>

instead of:


The reason is simple: extensions. Since any element in Fhir can be extended, there’s no such thing as a true “primitive” element. We might extend birthDate, so we could also include the original text as input by the user:

<birthDate value="2013-03-22">
        <url value="" />
        <valueString value="sometime next week" />

If we wouldn’t have put the actual value in an attribute, we would end up with mixed content for birthDate:

        <url value="" />
        <valueCode value="sometime next week" />

Handling mixed content is a pain for most of us, so we choose to use the “value” attribute over allowing mixed content.

Whether this really is out of line with current Xml authoring style is unclear: discussions on this subject on stackoverflow show a wide range of opinions, some even prefer to always put primitive values in attributes. It is however, clearly more painful for those using JSON, where any member is now expanded to a complex object:

"birthDate": {"value": "1973-05-31"}

instead of the more natural

"birthDate": "1973-05-31"