@@ -122,21 +122,26 @@ def get_values(self, value_list):
122
122
return value_seq
123
123
124
124
def write_file (self , odml_document , filename ):
125
+ file = open (filename , 'w' )
126
+ file .write (self .to_string (odml_document ))
127
+ file .close ()
128
+
129
+ def to_string (self , odml_document ):
130
+ string_doc = ''
125
131
126
132
if self .parser == 'XML' or self .parser == 'ODML' :
127
- xmlparser .XMLWriter (odml_document ). write_file ( filename )
133
+ string_doc = str ( xmlparser .XMLWriter (odml_document ))
128
134
else :
129
135
self .to_dict (odml_document )
130
136
odml_output = {}
131
137
odml_output ['Document' ] = self .parsed_doc
132
138
odml_output ['odml-version' ] = odml_version
133
139
134
- f = open (filename , 'w' )
135
140
if self .parser == 'YAML' :
136
- f . write ( yaml .dump (odml_output , default_flow_style = False ) )
141
+ string_doc = yaml .dump (odml_output , default_flow_style = False )
137
142
elif self .parser == 'JSON' :
138
- f . write ( json .dumps (odml_output , indent = 4 ) )
139
- f . close ()
143
+ string_doc = json .dumps (odml_output , indent = 4 )
144
+ return string_doc
140
145
141
146
142
147
class ODMLReader :
@@ -253,7 +258,7 @@ def parse_values(self, value_list):
253
258
return odml_values
254
259
255
260
256
- def fromFile (self , file ):
261
+ def from_file (self , file ):
257
262
258
263
if self .parser == 'XML' or self .parser == 'ODML' :
259
264
odml_doc = xmlparser .XMLReader ().fromFile (file )
@@ -281,7 +286,7 @@ def fromFile(self, file):
281
286
return self .to_odml ()
282
287
283
288
284
- def fromString (self , string ):
289
+ def from_string (self , string ):
285
290
286
291
if self .parser == 'XML' or self .parser == 'ODML' :
287
292
odml_doc = xmlparser .XMLReader ().fromString (string )
0 commit comments