def parent_map(xml):
    """Creates the parent map dictionary, a map from child to parent in the XML hierarchy."""
    try:
        return xml.pm
    except AttributeError:
        xml.pm = {c:p for p in xml.iter() for c in p}
    return xml.pm