def lookup_schema_target_namespace(e):
    """
    For the given BaseSchema element find the target namespace. The
    targetNamespace is that of this element or if not defined it is that
    of the first parent element which has targetNamespace attribute
    defined.
    """
    if 'targetNamespace' in e.attrib:
        return e.attrib.get('targetNamespace')
    # FutureWarning: The behavior of this method will change in future
    # versions. Use specific 'len(elem)' or 'elem is not None' test
    # instead.
    if e.getparent() is not None:
        return lookup_schema_target_namespace(e.getparent())