Skip to content

Commit d5ef7e6

Browse files
added xml serialization to the base_type file
1 parent 9f8c144 commit d5ef7e6

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/modelspec/base_types.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import bson
44
import xml.etree.ElementTree as ET
55
import xml.dom.minidom
6+
import xmltodict
67
import sys
78

89
import numpy as np
@@ -166,10 +167,10 @@ def from_bson(cls, bson_str: str) -> "Base":
166167
@classmethod
167168
def from_xml(cls, xml_str: str) -> "Base":
168169
"""Instantiate a Base object from an XML string"""
169-
from modelspec.utils import _parse_xml_element
170+
from modelspec.utils import element_to_dict
170171

171172
root = ET.fromstring(xml_str)
172-
data_dict = _parse_xml_element(root)
173+
data_dict = element_to_dict(root)
173174
return cls.from_dict(data_dict)
174175

175176
def to_json_file(
@@ -400,13 +401,13 @@ def from_xml_file(cls, filename: str) -> "Base":
400401
Returns:
401402
A modelspec Base for this XML.
402403
"""
403-
from modelspec.utils import _parse_xml_element
404+
from modelspec.utils import element_to_dict
404405

405406
with open(filename) as infile:
406407
tree = ET.parse(filename)
407408
root = tree.getroot()
408409

409-
data_dict = _parse_xml_element(root)
410+
data_dict = element_to_dict(root)
410411
return cls.from_dict(data_dict)
411412

412413
def get_child(self, id: str, type_: str) -> Any:

0 commit comments

Comments
 (0)