from typing import OrderedDict


def _top_level_tags(form):
        """
        Returns a OrderedDict of the top level tags found in the xml, in the
        order they are found.

        """
        to_return = OrderedDict()

        element = form.get_xml_element()
        if element is None:
            return OrderedDict(sorted(form.form_data.items()))

        for child in element:
            # fix {namespace}tag format forced by ElementTree in certain cases (eg, <reg> instead of <n0:reg>)
            key = child.tag.split('}')[1] if child.tag.startswith("{") else child.tag
            if key == "Meta":
                key = "meta"
            to_return[key] = form.get_data('form/' + key)
        return to_return