Iterates over all the elements in an iterparse context
        (here: <document> elements) and yields an URMLDocumentGraph instance
        for each of them. For efficiency, the elements are removed from the
        DOM / main memory after processing them.

        If ``self.debug`` is set to ``True`` (in the ``__init__`` method),
        this method will yield <documents> elements, which can be used to
        construct ``URMLDocumentGraph``s manually.

def document_iter(self, context):
        """
        Iterates over all the elements in an iterparse context
        (here: <document> elements) and yields an URMLDocumentGraph instance
        for each of them. For efficiency, the elements are removed from the
        DOM / main memory after processing them.

        If ``self.debug`` is set to ``True`` (in the ``__init__`` method),
        this method will yield <documents> elements, which can be used to
        construct ``URMLDocumentGraph``s manually.
        """
        for _event, elem in context:
            if not self.debug:
                yield URMLDocumentGraph(elem, tokenize=self.tokenize,
                                        precedence=self.precedence)
            else:
                yield elem
            # removes element (and references to it) from memory after processing it
            elem.clear()
            while elem.getprevious() is not None:
                del elem.getparent()[0]
        del context