Reputation:
Empty value attributes aren't allowed, so we need to remove the url but I am not sure the best way to do it in code?
Can I just use RemoveExtension?
foreach (var RelatedArtifact in target.RelatedArtifact)
{
if (string.IsNullOrEmpty(RelatedArtifact.Url))
{
RelatedArtifact.RemoveExtension("url");
//Remove URI tag
}
}
Output file
<relatedArtifact>
<type value="citation" />
<display value="eeee, et al. eee. eee;ee(ee):eee." />
<url value="" />
</relatedArtifact>
Upvotes: 1
Views: 308
Reputation: 2299
To clarify, we're talking about the .Net FHIR library here, which has a RemoveExtension method.
The answer is: no, you cannot just use that method to get rid of any empty element called url.
The RemoveExtension can be used to remove an extension from the object, by supplying the method with the canonical url of the extension you want to remove.
See http://hl7.org/fhir/extensibility.html for more info about extensions.
The .Net FHIR library will not serialize empty elements if you use the library's serializer, so RelatedArtifact.Url being empty should already be good enough. So the best way to do this in code, is to make use of the FhirXmlSerializer. If you find that that produces invalid FHIR xml, please raise an issue with an explanation of what you tried on the fhir-net-api Github.
Upvotes: 1