def get_ns(tag):
    """
        Extract namespace.

        This function is opposite to get_local_name, in that
        it returns the first part of the tag: the namespace.

        Parameters
        ----------
        tag : str
            Tag to process.
    """
    p_open = tag.find('{')
    p_close = tag.find('}')
    if p_open != -1 and p_close != -1:
        return tag[p_open+1:p_close]
    else:
        return ''