DEFAULT_NS = 'http://www.domain.org/path/to/xml'

def add_xml_namespace(path, namespace=DEFAULT_NS):
    """Adds namespaces to an XPath-ish expression path for etree
    Test simple expression:
    >>> add_xml_namespace('image/namingData/fileBaseName')
    '{http://www.domain.org/path/to/xml}image/{http://www.domain.org/path/to/xml}namingData/{http://www.domain.org/path/to/xml}fileBaseName'
    More complicated expression
    >>> add_xml_namespace('.//image/*') 
    './/{http://www.domain.org/path/to/xml}image/*'
    >>> add_xml_namespace('.//image/text()')
    './/{http://www.domain.org/path/to/xml}image/text()'
    """
pattern = re.compile('^[A-Za-z0-9-]+$')
tags = path.split('/')
for i in range(len(tags)):
    if pattern.match(tags[i]):
        tags[i] = '{%s}%s' % (namespace, tags[i])
return '/'.join(tags)
Python плохо работает с XML?