diff --git a/xmlutils/xml2json.py b/xmlutils/xml2json.py index a057823..768505e 100644 --- a/xmlutils/xml2json.py +++ b/xmlutils/xml2json.py @@ -30,16 +30,21 @@ def __init__(self, input_file, output_file = None, encoding='utf-8'): def get_json(self, pretty=True): """ - Convert an XML file to json string + Convert an XML file to json string (Tested with python 2.7.8 on Windows 7) Keyword arguments: pretty -- pretty print json (default=True) """ - self.context = iter(self.context) - event, root = self.context.next() + iterator = iter(self.context) - return self._elem2json(root, pretty) + try: + while True: + event, root = iterator.next() + except StopIteration: + print("Event StopIteration found, done!") + finally: + return self._elem2json(root, pretty) def convert(self, pretty=True): """