def untlxml2py(untl_filename):
    parent_stack = []
    for event, element in iterparse(untl_filename, events=('start', 'end')):
        if NAMESPACE_REGEX.search(element.tag, 0):
            element_tag = NAMESPACE_REGEX.search(element.tag, 0).group(1)
        else:
            element_tag = element.tag
        if element_tag in PYUNTL_DISPATCH:
            if event == 'start':
                parent_stack.append(PYUNTL_DISPATCH[element_tag]())
            elif event == 'end':
                child = parent_stack.pop()
                if element.text is not None:
                    content = element.text.strip()
                    if content != '':
                        child.set_content(element.text)
                if element.get('qualifier', False):
                    child.set_qualifier(element.get('qualifier'))
                if len(parent_stack) > 0:
                    parent_stack[-1].add_child(child)
                else:
                    return child
        else:
            raise PyuntlException(
                'Element "%s" not in UNTL dispatch.' % (element_tag)
            )