def get_all_attrs(elem):
    """Returns attribute and value pairs from all the elements in the subtree
    of lxml.etree._Element, including the given element.
    """
    attrs = []
    for e in elem.iter():
        attrs += e.attrib.items()
    return attrs