import re


def extractNamespaces(doc):
    """Extract xmlns:prefix="namespace" pairs from the root element of the
    XML document and return a dictionary.  The default namespace (xmlns="ns")
    is also extracted and saved under the null ('') prefix.
    """
    ns = {}
    match = re.search(r'<\w+ .*?>', doc, re.DOTALL)
    if match:
        rootElement = match.group(0)
        match = re.search(r'xmlns=[\'"](.*?)[\'"]', rootElement, re.DOTALL)
        if match:
            ns['_'] = match.group(1)   # default namespace
            ns[''] = match.group(1)
            ns['_default'] = match.group(1)
        matches = re.finditer(
            r'xmlns:(\w+?)=[\'"](.*?)[\'"]', rootElement, re.DOTALL)
        for match in matches:
            ns[match.group(1)] = match.group(2)   # prefix = ns
    return ns