handle xml default namespace for logical model

This commit is contained in:
Oliver Egger 2020-08-26 16:53:50 +02:00
parent 78926f207d
commit 23cce5b0a7
3 changed files with 22 additions and 13 deletions

View File

@ -188,7 +188,7 @@ public class XmlParser extends ParserBase {
String name = element.getLocalName(); String name = element.getLocalName();
String path = "/"+pathPrefix(ns)+name; 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) if (sd == null)
return 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 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); logError(line(element), col(element), path, IssueType.INVALID, context.formatMessage(I18nConstants.ELEMENT_MUST_HAVE_SOME_CONTENT), IssueSeverity.ERROR);
String ns = prop.getXmlNamespace(); 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); 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.setSortAttributes(false);
xml.setPretty(style == OutputStyle.PRETTY); xml.setPretty(style == OutputStyle.PRETTY);
xml.start(); xml.start();
xml.setDefaultNamespace(e.getProperty().getXmlNamespace()); String ns = e.getProperty().getXmlNamespace();
if (ns!=null && !"default".equals(ns)) {
xml.setDefaultNamespace(ns);
}
if (hasTypeAttr(e)) if (hasTypeAttr(e))
xml.namespace("http://www.w3.org/2001/XMLSchema-instance", "xsi"); xml.namespace("http://www.w3.org/2001/XMLSchema-instance", "xsi");
addNamespaces(xml, e); addNamespaces(xml, e);
@ -549,7 +556,7 @@ public class XmlParser extends ParserBase {
private void addNamespaces(IXMLWriter xml, Element e) throws IOException { private void addNamespaces(IXMLWriter xml, Element e) throws IOException {
String ns = e.getProperty().getXmlNamespace(); 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)) { if (!xml.namespaceDefined(ns)) {
String prefix = pathPrefix(ns); String prefix = pathPrefix(ns);
if (prefix.endsWith(":")) { if (prefix.endsWith(":")) {

View File

@ -450,7 +450,7 @@ public class XMLWriter extends OutputStreamWriter implements IXMLWriter {
if ("http://www.w3.org/XML/1998/namespace".equals(namespace)) if ("http://www.w3.org/XML/1998/namespace".equals(namespace))
return "xml:"; return "xml:";
if (namespace == null || "".equals(namespace)) if (namespace == null || "".equals(namespace) || "default".equals(namespace))
return ""; return "";
XMLNamespace ns = findByNamespace(namespace); XMLNamespace ns = findByNamespace(namespace);

View File

@ -212,14 +212,16 @@ public class ValidationTestSuite implements IEvaluationContext, IValidatorResour
if (content.has("security-checks")) { if (content.has("security-checks")) {
val.setSecurityChecks(content.get("security-checks").getAsBoolean()); val.setSecurityChecks(content.get("security-checks").getAsBoolean());
} }
val.setAssumeValidRestReferences(content.has("assumeValidRestReferences") ? content.get("assumeValidRestReferences").getAsBoolean() : false); if (content.has("logical")==false) {
System.out.println(String.format("Start Validating (%d to set up)", (System.nanoTime() - setup) / 1000000)); val.setAssumeValidRestReferences(content.has("assumeValidRestReferences") ? content.get("assumeValidRestReferences").getAsBoolean() : false);
if (name.endsWith(".json")) System.out.println(String.format("Start Validating (%d to set up)", (System.nanoTime() - setup) / 1000000));
val.validate(null, errors, IOUtils.toInputStream(testCaseContent, Charsets.UTF_8), FhirFormat.JSON); if (name.endsWith(".json"))
else val.validate(null, errors, IOUtils.toInputStream(testCaseContent, Charsets.UTF_8), FhirFormat.JSON);
val.validate(null, errors, IOUtils.toInputStream(testCaseContent, Charsets.UTF_8), FhirFormat.XML); else
System.out.println(val.reportTimes()); val.validate(null, errors, IOUtils.toInputStream(testCaseContent, Charsets.UTF_8), FhirFormat.XML);
checkOutcomes(errors, content, null); System.out.println(val.reportTimes());
checkOutcomes(errors, content, null);
}
if (content.has("profile")) { if (content.has("profile")) {
System.out.print("** Profile: "); System.out.print("** Profile: ");
JsonObject profile = content.getAsJsonObject("profile"); JsonObject profile = content.getAsJsonObject("profile");