def get_top_pb_type(element):
    """ Returns the top level pb_type given a subelement of the XML tree."""

    # Already top-level
    parent = element.getparent()
    if parent is not None and parent.tag == "complexblocklist":
        return None

    # Traverse
    while True:
        parent = element.getparent()

        if parent is None:
            return None
        if parent.tag == "complexblocklist":
            assert element.tag == "pb_type", element.tag
            return element

        element = parent