File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -247,13 +247,17 @@ def build_xml_element(data, parent=None):
247
247
Parent
248
248
"""
249
249
250
- # If a parent name isn't given, it extracts the name from the class and use that instead
251
250
if parent is None :
252
251
parent = ET .Element (data .__class__ .__name__ )
253
252
254
253
attrs = attr .fields (data .__class__ )
254
+ id_attribute_value = (
255
+ None # Store id attribute value to be set after other attributes
256
+ )
255
257
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 ):
257
261
children = data .__getattribute__ (aattr .name )
258
262
if not isinstance (children , (list , tuple )):
259
263
children = [children ]
@@ -279,6 +283,10 @@ def build_xml_element(data, parent=None):
279
283
if hasattr (data , "xmlns_loc" ):
280
284
parent .set ("xsi:schemaLocation" , str (data .xmlns_loc + "\n " + data .xmln_loc_2 ))
281
285
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
+
282
290
return parent
283
291
284
292
You can’t perform that action at this time.
0 commit comments