FHIR Chat · FHIR Narrative DIV tag with or without xmlns ? · implementers

Stream: implementers

Topic: FHIR Narrative DIV tag with or without xmlns ?


view this post on Zulip Mordekhai Oziel (Jul 17 2017 at 09:09):

Hi all,
when writing a resource that contains an xhtml div tag, is the xmlns attribute requested or optional ? When I have a look at the FHIR specs it is not mentioned but when I have a look at the HAPI validator source, this attribute is requested.
Thanks

view this post on Zulip Michel Rutten (Jul 17 2017 at 09:15):

Hi @Mordekhai Oziel, when you are serializing to XML, then I think you should always generate an XML namespace attribute on the div tag, as this element is not part of the FHIR namespace.

view this post on Zulip Mordekhai Oziel (Jul 17 2017 at 09:17):

Hi @Mordekhai Oziel, when you are serializing to XML, then I think you should always generate an XML namespace attribute on the div tag, as this element is not part of the FHIR namespace.

Thanks for your quick help

view this post on Zulip Mordekhai Oziel (Jul 17 2017 at 11:56):

Hi all,
is there a reason why in DSTU2 the validation of resources containing a div tag did not require an xmlns and from DSTU3 it seems to be required ?
Is it required only when serializing xml or also for a json resource containing such a div tag ?
Does anybody know why in FHIR specs(https://www.hl7.org/fhir/dstu2/narrative.html#xhtml) we can see that a div without xmlns is legal ?

"div": "<div>text</div>"
is legal, but this is not:

"div": "<?xml ...><div>text</div>"

Thanks

view this post on Zulip Vadim Peretokin (Jul 17 2017 at 12:10):

<?xml> is an XML declaration, that is different from the namespace xmlns declaration

view this post on Zulip Vadim Peretokin (Jul 17 2017 at 12:11):

The declaration might be not legal because it's just an xhtml snippet and not a full-blown, standalone XML document

view this post on Zulip Vadim Peretokin (Jul 17 2017 at 12:12):

See:

The XHTML content SHALL NOT contain a head, a body element, external stylesheet references, deprecated elements, scripts, forms, base/link/xlink, frames, iframes, objects or event related attributes

It's pretty stripped down

view this post on Zulip Michel Rutten (Jul 17 2017 at 12:49):

I think the XHTML Namespace on the div element is only required when serializing to XML. JSON doesn't have namespaces.
The <?xml... is a pre-processing tag that can only occur at the beginning of an XML document.

view this post on Zulip Mordekhai Oziel (Jul 17 2017 at 12:55):

I think the XHTML Namespace on the div element is only required when serializing to XML. JSON doesn't have namespaces.
The <?xml... is a pre-processing tag that can only occur at the beginning of an XML document.

Thank you @Michel Rutten , if I am correct, even when you write a JSON resource your div field contains xhtml and according to the HAPI validator, when you validate a JSON resource containing such a div tag without xmlns, you get an error.
I am a little bit confused here...

Thanks

view this post on Zulip Michel Rutten (Jul 17 2017 at 13:03):

Hi @Mordekhai Oziel, not sure about JSON validator, as I mainly work in XML space myself. The "<div...>...</div>" part is actually an XHTML fragment, not a complete document. Namespace on the div element could be useful/necessary when client logic wants to merge the fragment into a containing XHTML page, depending on the processing logic.

view this post on Zulip Michel Rutten (Jul 17 2017 at 13:05):

I think it's best to always include the namespace on div element in both XHTML and JSON, so the formats are interchangeable.

view this post on Zulip Mordekhai Oziel (Jul 17 2017 at 13:11):

Thank you @Michel Rutten , Sorry I should precise a little bit more of context:
I am writing a validation service that accepts FHIR resources in both XML and JSON formats, deserialize them and validate them.
We noticed that when we work on objects that contain div tags missing xmlns we get an error from the HAPI validator.
Here is an example:
{
"resourceType": "StructureDefinition",
...
"text": {
"status": "generated",
"div": "<div>abc</div>"
},
...
}

Here is the error: ERROR: StructureDefinition.text.div: Wrong namespace on the XHTML ('null')

According to the answers I got from you and @Vadim Peretokin , I understand that the xmlns should always be provided. But how can I say this is "mandatory" to my users when I can't see anything about it in the FHIR specs ?
Do you think it is an error from the validator that should accept div without xmlns or do you think FHIR specs are incomplete ?
Sorry to ask several times the same question but I am new to the FHIR world.

Thank you for your help

view this post on Zulip Vadim Peretokin (Jul 17 2017 at 13:27):

I see your point. It is mandatory for XML since it's a different namespace, but JSON doesn't have that idea of them. The .NET validator seems to be fine with it either way, and since nothing is mentioned about it in the spec, I'd say it seems HAPI is adding an extra constraint in here

view this post on Zulip Mordekhai Oziel (Jul 17 2017 at 13:40):

I see your point. It is mandatory for XML since it's a different namespace, but JSON doesn't have that idea of them. The .NET validator seems to be fine with it either way, and since nothing is mentioned about it in the spec, I'd say it seems HAPI is adding an extra constraint in here

Thanks a lot :+1:

view this post on Zulip Michel Rutten (Jul 18 2017 at 08:14):

Hi @Mordekhai Oziel, maybe you should discuss this with the HAPI team (@James Agnew)?

view this post on Zulip Mordekhai Oziel (Jul 18 2017 at 08:54):

Hi @Michel Rutten , thanks for this contact, I'll do.

view this post on Zulip Grahame Grieve (Jul 21 2017 at 10:45):

the spec says:
"The XHTML <div> element in the Narrative datatype is represented as a single escaped string of XHTML. This is to avoid problems in JSON with mixed content, etc. The XHTML SHALL still conform to the rules described for the Narrative"

view this post on Zulip Grahame Grieve (Jul 21 2017 at 10:46):

the rules for the narrative say that it is xhtml, according to the xhtml spec. So the namespace must be present, as shown in all the examples. We could make this a little more explicit in the JSON page, but it certainly must be present

view this post on Zulip Ewout Kramer (Jul 21 2017 at 12:26):

Yeah, that's something I should add. You can find it under https://github.com/ewoutkramer/fhir-net-api/issues/402


Last updated: Apr 12 2022 at 19:14 UTC