Extract select attributes from XSD into JSON.

This commit is contained in:
Dion Moult
2020-01-19 18:40:39 +11:00
parent 3fb268f687
commit a34588179d
+18 -3
View File
@@ -16,14 +16,16 @@ class IFC4Extractor:
#self.filters = ['IfcSpatialStructureElement']
#self.filters = ['IfcStructuralActivity', 'IfcStructuralItem']
#self.filters = ['IfcMaterialDefinition']
self.filters = ['IfcParameterizedProfileDef']
#self.filters = ['IfcParameterizedProfileDef']
self.filters = ['IfcBoundaryCondition']
self.filtered_elements = {}
def extract(self):
for element in self.root.findall("xs:element", self.ns):
#if self.is_descendant_from_class(element, "IfcRoot"):
#if self.is_descendant_from_class(element, "IfcMaterialDefinition"):
if self.is_descendant_from_class(element, "IfcParameterizedProfileDef"):
#if self.is_descendant_from_class(element, "IfcParameterizedProfileDef"):
if self.is_descendant_from_class(element, "IfcBoundaryCondition"):
print('Processing {}'.format(element.attrib['name']))
data = {
'is_abstract': self.is_abstract(element),
@@ -93,10 +95,23 @@ class IFC4Extractor:
})
else:
type_element = attribute.find('./xs:complexType/xs:sequence/xs:element[@ref]', self.ns)
is_select = False
select_types = []
if not type_element:
# Handle select (i.e. group) attributes
type_element = attribute.find('./xs:complexType/xs:group', self.ns)
if type_element is not None:
is_select = True
select_types = [e.attrib['ref'].replace('ifc:', '') for e in
self.root.findall("./xs:group[@name='{}']/xs:choice/xs:element[@ref]".format(
type_element.attrib['ref'].replace('ifc:', '')
), self.ns)]
if type_element is not None:
attributes.append({
'name': attribute.attrib['name'],
'type': type_element.attrib['ref'].replace('ifc:', '')
'type': type_element.attrib['ref'].replace('ifc:', ''),
'is_select': is_select,
'select_types': select_types
})
return attributes