diff --git a/src/ifcopenshell-python/ifcopenshell/ids.py b/src/ifcopenshell-python/ifcopenshell/ids.py index 44d5e069ae..7d4e9d2c0b 100644 --- a/src/ifcopenshell-python/ifcopenshell/ids.py +++ b/src/ifcopenshell-python/ifcopenshell/ids.py @@ -522,6 +522,27 @@ class ids: for spec in self.specifications: ids_dict['specification'].append(spec.asdict()) return ids_dict + + def to_xml(self, fn='./', ids_schema=ids_schema): + if fn.endswith('/'): + fn = fn + 'IDS' + if not fn.endswith('.xml'): + fn = fn + '.xml' + + ids_dict = self.asdict() + + ids_xml = ids_schema.encode(ids_dict) #, namespaces='http://standards.buildingsmart.org/IDS') + ids_str = etree_tostring(ids_xml, namespaces={'': 'http://standards.buildingsmart.org/IDS'}) # if restrictions, add also: 'xs': 'http://www.w3.org/2001/XMLSchema' + ids_schema.validate(ids_str) + + with open(fn, 'w') as f: + f.write('\n') + f.write('\n') + f.write(ids_str) + + ids_schema.validate(fn) + return ids_schema.is_valid(fn) + @staticmethod def parse(fn, ids_schema=ids_schema): ids_schema.validate(fn)