@@ -57,19 +57,16 @@ def parse_element_value(self, value: Optional[str]) -> Any:
57
57
raise ValueError ("Invalid XML file schema" )
58
58
59
59
# element type validation check
60
- match self :
61
- case XMLElementType .STRING :
62
- return value
63
- case XMLElementType .INTEGER :
64
- return int (value )
65
- case XMLElementType .FLOAT :
66
- return float (value )
67
- case XMLElementType .BOOLEAN :
68
- return value == "true"
69
- case _:
70
- raise NotImplementedError (
71
- f"Etree element type not supported: { self .value } "
72
- )
60
+ if self is XMLElementType .STRING :
61
+ return value
62
+ elif self is XMLElementType .INTEGER :
63
+ return int (value )
64
+ elif self is XMLElementType .FLOAT :
65
+ return float (value )
66
+ elif self is XMLElementType .BOOLEAN :
67
+ return value == "true"
68
+ else :
69
+ raise NotImplementedError (f"Etree element type not supported: { self .value } " )
73
70
74
71
75
72
class XMLParser :
@@ -145,30 +142,33 @@ def _parse_json_data_to_etree(data: JSONType) -> _Element:
145
142
element_value : Optional [str ] = None
146
143
147
144
# Set element children and value based on the type of the item
148
- match element_type :
149
- # if the element is an object, then assign children to element keys recursively
150
- case XMLElementType .OBJECT :
151
- for key , value in data .items (): # type: ignore
152
- child = XMLParser ._parse_json_data_to_etree (value )
153
- child .set ("key" , key )
154
- element .append (child )
155
- # if the element is a list, then append children to element
156
- case XMLElementType .LIST :
157
- for value in data : # type: ignore
158
- child = XMLParser ._parse_json_data_to_etree (value )
159
- element .append (child )
160
- # if the element type is a string leaf, then set the value of the element
161
- case XMLElementType .STRING :
162
- element_value = data # type: ignore
163
- # if the element type is a leaf and not a string, then set the json-dumped value of the element
164
- case XMLElementType .INTEGER | XMLElementType .FLOAT | XMLElementType .BOOLEAN :
165
- element_value = json .dumps (data )
166
- # if the element type is null, then do not set the value of the element
167
- case XMLElementType .NULL :
168
- pass
169
- # if the element type is not one of above type, then raise an error
170
- case _:
171
- raise NotImplementedError ("Unsupported type for parsing" )
145
+ # if the element is an object, then assign children to element keys recursively
146
+ if element_type is XMLElementType .OBJECT :
147
+ for key , value in data .items (): # type: ignore
148
+ child = XMLParser ._parse_json_data_to_etree (value )
149
+ child .set ("key" , key )
150
+ element .append (child )
151
+ # if the element is a list, then append children to element
152
+ elif element_type is XMLElementType .LIST :
153
+ for value in data : # type: ignore
154
+ child = XMLParser ._parse_json_data_to_etree (value )
155
+ element .append (child )
156
+ # if the element type is a string leaf, then set the value of the element
157
+ elif element_type is XMLElementType .STRING :
158
+ element_value = data # type: ignore
159
+ # if the element type is a leaf and not a string, then set the json-dumped value of the element
160
+ elif element_type in [
161
+ XMLElementType .INTEGER ,
162
+ XMLElementType .FLOAT ,
163
+ XMLElementType .BOOLEAN ,
164
+ ]:
165
+ element_value = json .dumps (data )
166
+ # if the element type is null, then do not set the value of the element
167
+ elif element_type is XMLElementType .NULL :
168
+ pass
169
+ # if the element type is not one of above type, then raise an error
170
+ else :
171
+ raise NotImplementedError ("Unsupported type for parsing" )
172
172
173
173
if element_value is not None :
174
174
element .set ("value" , element_value )
0 commit comments