Attributes versus Elements
Health Interoperability
1 Min Read

Attributes Versus Elements in FHIR XML

Ewout Kramer

Subscribe to our newsletter


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"

Want to stay on top of Interoperability and Health IT? 

Subscribe to our newsletter for the latest news on FHIR. 

3 thoughts

  1. grahamegrieve on said:

    Well, yes, but we already had foregone the opportunity for the more compact json representation because any primitive would need to have an id attribute anyway, so “birthDate”: “1973-05-31” was never an option 🙁

  2. Peter Bernhardt on said:

    As someone authoring a derivative spec where JSON is the only format we’ll support, yes, I do find this unnecessary and burdensome. Ewout, I understand that you’ve written a good C# parser for this that eases the pain – but what about Java, Perl, PHP, Python, etc? And to Grahame’s comment, do you really need an id attribute on a date? I know that’s just a simple example, but doesn’t defining a type as a CodeableConcept address the edge cases? i believe you folks have done an outstanding job with FHIR, but I’m very worried that something like this will give people pause – or force them to adopt XML as their only supported format. That the important goal at the heart of the FHIR spec – simplicity – has been sacrificed by this design decision.

    • Hi Peter, since we want to be able to refer to primitive values from the narrative, even primitives need to be able to receive id’s. They can also be extended, a good example would be an extension on a simple string to indicate the language. Another example is an extension to encode a null flavor on any primitive value…. it’s certainly not my favorite part of the design, but it’s too early to say we are not going to need it. That being said, DSTU is there to see whether this turns out to be a major pita and decide whether its advantages are worth the trouble…

Post a comment

Your email address will not be published. Required fields are marked *