Skip to content

Commit bb5a17d

Browse files
modified xml serialization code form much better appearance
1 parent 28e270f commit bb5a17d

File tree

1 file changed

+10
-26
lines changed

1 file changed

+10
-26
lines changed

src/modelspec/base_types.py

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,11 @@ def to_xml(self) -> str:
126126
build_xml_element(root, self.to_dict())
127127

128128
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")
131134

132135
parsed_xml = xml.dom.minidom.parseString(xml_string)
133136
pretty_xml = parsed_xml.toprettyxml(indent=" " * 4)
@@ -281,7 +284,11 @@ def to_xml_file(
281284
tree = ET.ElementTree(root)
282285

283286
# 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")
285292

286293
# Create a pretty-formatted XML string using minidom
287294
parsed_xml = xml.dom.minidom.parseString(xml_str)
@@ -293,29 +300,6 @@ def to_xml_file(
293300

294301
return filename
295302

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
319303

320304
@classmethod
321305
def from_file(cls, filename: str) -> "Base":

0 commit comments

Comments
 (0)