Skip to content

Commit 5371939

Browse files
modified the bulid xml element function to produce an almost perfect representation of the neuroml definition
1 parent f4ff85c commit 5371939

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/modelspec/utils.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,17 @@ def build_xml_element(data, parent=None):
247247
Parent
248248
"""
249249

250-
# If a parent name isn't given, it extracts the name from the class and use that instead
251250
if parent is None:
252251
parent = ET.Element(data.__class__.__name__)
253252

254253
attrs = attr.fields(data.__class__)
254+
id_attribute_value = (
255+
None # Store id attribute value to be set after other attributes
256+
)
255257
for aattr in attrs:
256-
if isinstance(aattr.default, attr.Factory):
258+
if aattr.name == "id":
259+
id_attribute_value = data.__getattribute__(aattr.name)
260+
elif isinstance(aattr.default, attr.Factory):
257261
children = data.__getattribute__(aattr.name)
258262
if not isinstance(children, (list, tuple)):
259263
children = [children]
@@ -279,6 +283,10 @@ def build_xml_element(data, parent=None):
279283
if hasattr(data, "xmlns_loc"):
280284
parent.set("xsi:schemaLocation", str(data.xmlns_loc + "\n" + data.xmln_loc_2))
281285

286+
# Set the id attribute after processing all other attributes
287+
if id_attribute_value is not None:
288+
parent.set("id", str(id_attribute_value))
289+
282290
return parent
283291

284292

0 commit comments

Comments
 (0)