#!/usr/local/bin/python2 from xml.etree.ElementTree import QName class QName(QName): __slots__ = '_namespace', '_localname', '_text' def __init__(self, text_or_uri, tag=None): if text_or_uri.startswith('{'): namespace, _, localname = text_or_uri[1:].rpartition('}') else: namespace = '' localname = text_or_uri if tag: self._namespace = namespace or localname self._localname = tag self._text = '{%s}%s' % (self._namespace, tag) elif namespace: self._namespace = namespace self._localname = localname self._text = text_or_uri else: self._namespace = None self._text = self._localname = localname @property def namespace(self): return self._namespace @property def localname(self): return self._localname @property def text(self): return self._text print QName('a', 'c').text