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:

<birthDate>1972-11-30</birthDate>

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">
    <extension>
        <url value="http://dontuse.example.org/profile/@narrative#originalText" />
        <valueString value="sometime next week" />
    </extension>
</birthDate>

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

<birthDate>
    2013-03-22
    <extension>
        <url value="http://hl7.org/fhir/profile/@narrative#originalText" />
        <valueCode value="sometime next week" />
    </extension>
</birthDate>

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"
Advertisements