FHIR Chat · XML Serialise Error · dotnet

Stream: dotnet

Topic: XML Serialise Error


view this post on Zulip Richard Kavanagh (Dec 22 2016 at 14:35):

I'm trying to serialise a resource to XML using the latest DSTU2 Nuget package. The code I am using is as follows

var tt = FhirSerializer.SerializeResourceToXml(_resource);

view this post on Zulip Richard Kavanagh (Dec 22 2016 at 14:36):

When the resource is an "OperationDefinition" it works fine

view this post on Zulip Richard Kavanagh (Dec 22 2016 at 14:37):

When the resource is a "ValueSet" it throws an exception as below

view this post on Zulip Richard Kavanagh (Dec 22 2016 at 14:37):

[XmlException: Data at the root level is invalid. Line 1, position 1.]
System.Xml.XmlTextReaderImpl.Throw(Exception e) +72
System.Xml.XmlTextReaderImpl.Throw(String res, String arg) +192
System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace() +341
System.Xml.XmlTextReaderImpl.ParseDocumentContent() +311
System.Xml.XmlTextReaderImpl.Read() +148
System.Xml.XmlReader.MoveToContent() +43
System.Xml.Linq.XElement.Load(XmlReader reader, LoadOptions options) +27
System.Xml.Linq.XElement.Parse(String text, LoadOptions options) +90
Hl7.Fhir.Serialization.XmlFhirWriter.WritePrimitiveContents(Object value, XmlSerializationHint xmlFormatHint) +117
Hl7.Fhir.Serialization.PrimitiveValueWriter.Serialize(Object value, XmlSerializationHint hint) +96
Hl7.Fhir.Serialization.DispatchingWriter.write(PropertyMapping prop, Object instance, SummaryType summary, SerializationMode mode) +74
Hl7.Fhir.Serialization.DispatchingWriter.Serialize(PropertyMapping prop, Object instance, SummaryType summary, SerializationMode mode) +281
Hl7.Fhir.Serialization.ComplexTypeWriter.write(ClassMapping mapping, Object instance, SummaryType summary, PropertyMapping prop, SerializationMode mode) +446
Hl7.Fhir.Serialization.ComplexTypeWriter.writeProperty(ClassMapping mapping, Object instance, SummaryType summary, SerializationMode mode, PropertyMapping prop) +563
Hl7.Fhir.Serialization.ComplexTypeWriter.Serialize(ClassMapping mapping, Object instance, SummaryType summary, SerializationMode mode) +426
Hl7.Fhir.Serialization.DispatchingWriter.write(PropertyMapping prop, Object instance, SummaryType summary, SerializationMode mode) +290
Hl7.Fhir.Serialization.DispatchingWriter.Serialize(PropertyMapping prop, Object instance, SummaryType summary, SerializationMode mode) +281
Hl7.Fhir.Serialization.ComplexTypeWriter.write(ClassMapping mapping, Object instance, SummaryType summary, PropertyMapping prop, SerializationMode mode) +446
Hl7.Fhir.Serialization.ComplexTypeWriter.writeProperty(ClassMapping mapping, Object instance, SummaryType summary, SerializationMode mode, PropertyMapping prop) +563
Hl7.Fhir.Serialization.ComplexTypeWriter.Serialize(ClassMapping mapping, Object instance, SummaryType summary, SerializationMode mode) +426
Hl7.Fhir.Serialization.ResourceWriter.Serialize(Object instance, SummaryType summary, Boolean contained, String root) +822
Hl7.Fhir.Serialization.<>c__DisplayClass1_0.<SerializeToXml>b__0(XmlWriter xw) +128
Hl7.Fhir.Serialization.FhirSerializer.xmlWriterToString(Action`1 serializer) +123
Hl7.Fhir.Serialization.FhirSerializer.SerializeToXml(Base data, SummaryType summary, String root) +77
Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToXml(Resource resource, SummaryType summary) +7

view this post on Zulip Richard Kavanagh (Dec 22 2016 at 14:38):

Any ideas what might be causing this?

view this post on Zulip Michel Rutten (Dec 22 2016 at 14:53):

Hi @Richard Kavanagh I cannot reproduce the error using some example ValueSets. Can you share your own ValueSet resource for debugging purposes?

view this post on Zulip Richard Kavanagh (Dec 22 2016 at 14:57):

Strangely enough, it is one of the V2 valuesets from the core pack. If I serialise it as JSON it works fine.

view this post on Zulip Richard Kavanagh (Dec 22 2016 at 15:00):

The JSON serialisation is

view this post on Zulip Richard Kavanagh (Dec 22 2016 at 15:01):

{
"resourceType": "ValueSet",
"id": "v2-0717",
"meta": {
"profile": [
"http://hl7.org/fhir/StructureDefinition/valueset-shareable-definition"
]
},
"text": {
"status": "additional",
"div": "removed"
},
"url": "http://hl7.org/fhir/ValueSet/v2-0717",
"version": "2.8.2",
"name": "v2 Access Restriction Value",
"status": "active",
"experimental": true,
"publisher": "HL7, Inc",
"codeSystem": {
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/valueset-oid",
"valueUri": "urn:oid:2.16.840.1.133883.18.388"
}
],
"system": "http://hl7.org/fhir/v2/0717",
"caseSensitive": false,
"concept": [
{
"code": "ALL",
"display": "All"
},
{
"code": "DEM",
"display": "All demographic data"
},
{
"code": "DRG",
"display": "Drug"
},
{
"code": "HIV",
"display": "HIV status and results"
},
{
"code": "LOC",
"display": "Patient Location"
},
{
"code": "NO",
"display": "None"
},
{
"code": "OI",
"display": "Opt in all registries (HIPAA)"
},
{
"code": "OO",
"display": "Opt out all registries (HIPAA)"
},
{
"code": "PID-17",
"display": "Religion"
},
{
"code": "PID-7",
"display": "Date of Birth"
},
{
"code": "PSY",
"display": "Psychiatric Mental health"
},
{
"code": "SMD",
"display": "Sensitive medical data"
},
{
"code": "STD",
"display": "Sexually transmitted diseases"
}
]
}
}

view this post on Zulip Michel Rutten (Dec 22 2016 at 15:07):

@Richard Kavanagh Indeed, with this valueset I can reproduce the issue. I'll register a ticket so Ewout can investigate and solve the bug after his vacation.

view this post on Zulip Richard Kavanagh (Dec 22 2016 at 15:07):

I found the issue..

view this post on Zulip Richard Kavanagh (Dec 22 2016 at 15:08):

I'll raise the issue on GitHub

view this post on Zulip Michel Rutten (Dec 22 2016 at 15:09):

Looks like the serializer fails on this line: "div": "removed"
The "removed" element contents is not valid Xhtml...

view this post on Zulip Michel Rutten (Dec 22 2016 at 15:09):

This should be something like "<p>removed</p>"

view this post on Zulip Richard Kavanagh (Dec 22 2016 at 15:10):

Yes - I found that... eventually !!

view this post on Zulip Michel Rutten (Dec 22 2016 at 15:10):

But it would be nice if the API would handle this gracefully.

view this post on Zulip Michel Rutten (Dec 22 2016 at 15:12):

If you're going to register an issue on github, you can mention this as it will help to solve the issue quickly.

view this post on Zulip Richard Kavanagh (Dec 22 2016 at 15:12):

I guess technically as the text is typed as XHTML then it should accept text without tags. XHTML does not require any tags

view this post on Zulip Richard Kavanagh (Dec 22 2016 at 15:13):

See the examples here

view this post on Zulip Richard Kavanagh (Dec 22 2016 at 15:13):

http://www.hl7.org/implement/standards/fhir/narrative.html#Narrative

view this post on Zulip Michel Rutten (Dec 22 2016 at 15:15):

I guess it depends on how strict we want to define the standard. Strictly speaking valid Xhtml should always have a root element.

view this post on Zulip Michel Rutten (Dec 22 2016 at 15:16):

Well spec is clear, we should accept plain text.

view this post on Zulip Richard Kavanagh (Dec 22 2016 at 15:22):

To be honest I suspect the code is right and the spec probably needs work. I'll leave that for Ewout to progress if required. A more graceful exception would be useful though.

view this post on Zulip Richard Kavanagh (Dec 22 2016 at 15:22):

Issue #281 raised on github

view this post on Zulip Michel Rutten (Dec 22 2016 at 15:24):

Agreed, and thank you!


Last updated: Apr 12 2022 at 19:14 UTC