File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4545import json
4646import optparse
4747import sys
48- import os
4948
5049import xml .etree .cElementTree as ET
50+ from xml .dom import minidom
5151
5252
5353def strip_tag (tag ):
@@ -126,14 +126,6 @@ def internal_to_elem(pfsh, factory=ET.Element):
126126 sublist = []
127127 tags = list (pfsh .keys ())
128128
129- # workaround 'cannot convert boolean error'
130- def sani_value (v ):
131- if v == u'true' :
132- return '1'
133- elif v == u'false' :
134- return '0'
135- return v
136-
137129 # Allow deeply nested structures
138130 for tag in tags :
139131 value = pfsh [tag ]
@@ -156,13 +148,13 @@ def sani_value(v):
156148 else :
157149 sublist .append (internal_to_elem ({k : v }, factory = factory ))
158150 else :
159- text = sani_value ( value )
151+ text = value
160152 e = factory (tag , attribs )
161153
162154 for sub in sublist :
163155 e .append (sub )
164- e .text = text
165- e .tail = tail
156+ e .text = unicode ( text )
157+ e .tail = unicode ( tail )
166158 return e
167159
168160
@@ -211,7 +203,7 @@ def json2xml(json_data, factory=ET.Element):
211203 json_data = json .loads (json_data )
212204
213205 elem = internal_to_elem (json_data , factory )
214- return ET .tostring (elem )
206+ return minidom . parseString ( ET .tostring (elem )). toprettyxml ( indent = ' \t ' )
215207
216208
217209def main ():
You can’t perform that action at this time.
0 commit comments