fix parsing logical model list attributes

This commit is contained in:
Grahame Grieve 2023-09-29 13:34:19 +10:00
parent 69526476ba
commit 104973a1d9
1 changed files with 23 additions and 6 deletions

View File

@ -38,7 +38,9 @@ import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
@ -361,10 +363,16 @@ public class XmlParser extends ParserBase {
if (property.getName().equals("value") && element.isPrimitive()) if (property.getName().equals("value") && element.isPrimitive())
element.setValue(av); element.setValue(av);
else { else {
Element n = new Element(property.getName(), property, property.getType(), av).markLocation(line, col); String[] vl = {av};
if (property.isList() && av.contains(" ")) {
vl = av.split(" ");
}
for (String v : vl) {
Element n = new Element(property.getName(), property, property.getType(), v).markLocation(line, col);
n.setPath(element.getPath()+"."+property.getName()); n.setPath(element.getPath()+"."+property.getName());
element.getChildren().add(n); element.getChildren().add(n);
} }
}
} else { } else {
boolean ok = false; boolean ok = false;
if (FormatUtilities.FHIR_NS.equals(node.getNamespaceURI())) { if (FormatUtilities.FHIR_NS.equals(node.getNamespaceURI())) {
@ -739,11 +747,20 @@ public class XmlParser extends ParserBase {
} }
} else { } else {
setXsiTypeIfIsTypeAttr(xml, element); setXsiTypeIfIsTypeAttr(xml, element);
Set<String> handled = new HashSet<>();
for (Element child : element.getChildren()) { for (Element child : element.getChildren()) {
if (isAttr(child.getProperty()) && wantCompose(element.getPath(), child)) { if (!handled.contains(child.getName()) && isAttr(child.getProperty()) && wantCompose(element.getPath(), child)) {
handled.add(child.getName());
String av = child.getValue();
if (child.getProperty().isList()) {
for (Element c2 : element.getChildren()) {
if (c2 != child && c2.getName().equals(child.getName())) {
av = av + " "+c2.getValue();
}
}
}
if (linkResolver != null) if (linkResolver != null)
xml.link(linkResolver.resolveType(child.getType())); xml.link(linkResolver.resolveType(child.getType()));
String av = child.getValue();
if (ToolingExtensions.hasExtension(child.getProperty().getDefinition(), ToolingExtensions.EXT_DATE_FORMAT)) if (ToolingExtensions.hasExtension(child.getProperty().getDefinition(), ToolingExtensions.EXT_DATE_FORMAT))
av = convertForDateFormatToExternal(ToolingExtensions.readStringExtension(child.getProperty().getDefinition(), ToolingExtensions.EXT_DATE_FORMAT), av); av = convertForDateFormatToExternal(ToolingExtensions.readStringExtension(child.getProperty().getDefinition(), ToolingExtensions.EXT_DATE_FORMAT), av);
xml.attribute(child.getProperty().getXmlNamespace(),child.getProperty().getXmlName(), av); xml.attribute(child.getProperty().getXmlNamespace(),child.getProperty().getXmlName(), av);