@@ -126,8 +126,11 @@ def to_xml(self) -> str:
126
126
build_xml_element (root , self .to_dict ())
127
127
128
128
xml_string = ET .tostring (
129
- root , encoding = "utf-8" , xml_declaration = False , method = "xml"
130
- ).decode ("utf-8" )
129
+ root ,
130
+ encoding = "utf-8" ,
131
+ xml_declaration = False ,
132
+ method = "xml"
133
+ ).decode ("utf-8" )
131
134
132
135
parsed_xml = xml .dom .minidom .parseString (xml_string )
133
136
pretty_xml = parsed_xml .toprettyxml (indent = " " * 4 )
@@ -281,7 +284,11 @@ def to_xml_file(
281
284
tree = ET .ElementTree (root )
282
285
283
286
# Generate the XML string
284
- xml_str = ET .tostring (root , encoding = "utf-8" , method = "xml" ).decode ("utf-8" )
287
+ xml_str = ET .tostring (
288
+ root ,
289
+ encoding = "utf-8" ,
290
+ method = "xml"
291
+ ).decode ("utf-8" )
285
292
286
293
# Create a pretty-formatted XML string using minidom
287
294
parsed_xml = xml .dom .minidom .parseString (xml_str )
@@ -293,29 +300,6 @@ def to_xml_file(
293
300
294
301
return filename
295
302
296
- # def to_xml_file(self, filename: Optional[str] = None, include_metadata: bool = True) -> str:
297
- # from modelspec.utils import build_xml_element
298
- # if filename is None:
299
- # filename = f"{self.id}.xml"
300
-
301
- # root = ET.Element("root") # Create the root element
302
-
303
- # # Convert self to dictionary representation (assuming self.to_dict() returns a dictionary)
304
- # model_dict = self.to_dict()
305
-
306
- # # Create XML elements based on the dictionary
307
- # build_xml_element(root, model_dict)
308
-
309
- # xml_data = ET.tostring(root, encoding="utf-8", xml_declaration=True)
310
-
311
- # # Create a pretty-formatted XML string using minidom
312
- # xml_dom = xml.dom.minidom.parseString(xml_data)
313
- # pretty_xml_str = xml_dom.toprettyxml(indent=" ")
314
-
315
- # with open(filename, "w") as file:
316
- # file.write(pretty_xml_str)
317
-
318
- # return filename
319
303
320
304
@classmethod
321
305
def from_file (cls , filename : str ) -> "Base" :
0 commit comments