diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java index 3391f9bec..e2a7c641a 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java @@ -188,7 +188,7 @@ public class XmlParser extends ParserBase { String name = element.getLocalName(); String path = "/"+pathPrefix(ns)+name; - StructureDefinition sd = getDefinition(line(element), col(element), ns, name); + StructureDefinition sd = getDefinition(line(element), col(element), (ns == null ? "default" : ns), name); if (sd == null) return null; @@ -240,7 +240,11 @@ public class XmlParser extends ParserBase { if (empty(element) && FormatUtilities.FHIR_NS.equals(element.getNamespaceURI())) // this rule only applies to FHIR Content logError(line(element), col(element), path, IssueType.INVALID, context.formatMessage(I18nConstants.ELEMENT_MUST_HAVE_SOME_CONTENT), IssueSeverity.ERROR); String ns = prop.getXmlNamespace(); - if (!element.getNamespaceURI().equals(ns)) + String elementNs = element.getNamespaceURI(); + if (elementNs == null) { + elementNs = "default"; + } + if (!elementNs.equals(ns)) logError(line(element), col(element), path, IssueType.INVALID, context.formatMessage(I18nConstants.WRONG_NAMESPACE__EXPECTED_, ns), IssueSeverity.ERROR); } } @@ -539,7 +543,10 @@ public class XmlParser extends ParserBase { xml.setSortAttributes(false); xml.setPretty(style == OutputStyle.PRETTY); xml.start(); - xml.setDefaultNamespace(e.getProperty().getXmlNamespace()); + String ns = e.getProperty().getXmlNamespace(); + if (ns!=null && !"default".equals(ns)) { + xml.setDefaultNamespace(ns); + } if (hasTypeAttr(e)) xml.namespace("http://www.w3.org/2001/XMLSchema-instance", "xsi"); addNamespaces(xml, e); @@ -549,7 +556,7 @@ public class XmlParser extends ParserBase { private void addNamespaces(IXMLWriter xml, Element e) throws IOException { String ns = e.getProperty().getXmlNamespace(); - if (ns!=null && !xml.getDefaultNamespace().equals(ns)){ + if (ns!=null && xml.getDefaultNamespace()!=null && !xml.getDefaultNamespace().equals(ns)){ if (!xml.namespaceDefined(ns)) { String prefix = pathPrefix(ns); if (prefix.endsWith(":")) { diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/XMLWriter.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/XMLWriter.java index 107638ef5..fd4fec5bc 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/XMLWriter.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/XMLWriter.java @@ -450,7 +450,7 @@ public class XMLWriter extends OutputStreamWriter implements IXMLWriter { if ("http://www.w3.org/XML/1998/namespace".equals(namespace)) return "xml:"; - if (namespace == null || "".equals(namespace)) + if (namespace == null || "".equals(namespace) || "default".equals(namespace)) return ""; XMLNamespace ns = findByNamespace(namespace); diff --git a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationTestSuite.java b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationTestSuite.java index ba07c6403..dfd6b8d99 100644 --- a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationTestSuite.java +++ b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationTestSuite.java @@ -212,14 +212,16 @@ public class ValidationTestSuite implements IEvaluationContext, IValidatorResour if (content.has("security-checks")) { val.setSecurityChecks(content.get("security-checks").getAsBoolean()); } - val.setAssumeValidRestReferences(content.has("assumeValidRestReferences") ? content.get("assumeValidRestReferences").getAsBoolean() : false); - System.out.println(String.format("Start Validating (%d to set up)", (System.nanoTime() - setup) / 1000000)); - if (name.endsWith(".json")) - val.validate(null, errors, IOUtils.toInputStream(testCaseContent, Charsets.UTF_8), FhirFormat.JSON); - else - val.validate(null, errors, IOUtils.toInputStream(testCaseContent, Charsets.UTF_8), FhirFormat.XML); - System.out.println(val.reportTimes()); - checkOutcomes(errors, content, null); + if (content.has("logical")==false) { + val.setAssumeValidRestReferences(content.has("assumeValidRestReferences") ? content.get("assumeValidRestReferences").getAsBoolean() : false); + System.out.println(String.format("Start Validating (%d to set up)", (System.nanoTime() - setup) / 1000000)); + if (name.endsWith(".json")) + val.validate(null, errors, IOUtils.toInputStream(testCaseContent, Charsets.UTF_8), FhirFormat.JSON); + else + val.validate(null, errors, IOUtils.toInputStream(testCaseContent, Charsets.UTF_8), FhirFormat.XML); + System.out.println(val.reportTimes()); + checkOutcomes(errors, content, null); + } if (content.has("profile")) { System.out.print("** Profile: "); JsonObject profile = content.getAsJsonObject("profile");