handle xml default namespace for logical model
This commit is contained in:
parent
78926f207d
commit
23cce5b0a7
|
@ -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(":")) {
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -212,6 +212,7 @@ 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());
|
||||||
}
|
}
|
||||||
|
if (content.has("logical")==false) {
|
||||||
val.setAssumeValidRestReferences(content.has("assumeValidRestReferences") ? content.get("assumeValidRestReferences").getAsBoolean() : 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));
|
System.out.println(String.format("Start Validating (%d to set up)", (System.nanoTime() - setup) / 1000000));
|
||||||
if (name.endsWith(".json"))
|
if (name.endsWith(".json"))
|
||||||
|
@ -220,6 +221,7 @@ public class ValidationTestSuite implements IEvaluationContext, IValidatorResour
|
||||||
val.validate(null, errors, IOUtils.toInputStream(testCaseContent, Charsets.UTF_8), FhirFormat.XML);
|
val.validate(null, errors, IOUtils.toInputStream(testCaseContent, Charsets.UTF_8), FhirFormat.XML);
|
||||||
System.out.println(val.reportTimes());
|
System.out.println(val.reportTimes());
|
||||||
checkOutcomes(errors, content, null);
|
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");
|
||||||
|
|
Loading…
Reference in New Issue