[XML-SIG] Reconsidering NamespaceErr on '' and None

Rich Salz rsalz@zolera.com
Fri, 14 Dec 2001 11:20:52 -0500


I will answer my own question.

cDomlette uses empty string for the no namespace
	<foo id='fid'>
I have to call getAttributeNS('', 'id')

ZSI supports run-time DOM selection, so now my DOM-portable code looks
like this:
  try:
    from xml.dom import EMPTY_NAMESPACE
    _empty_nsuri_list = [ EMPTY_NAMESPACE ]
    if '' not in _empty_nsuri_list: __empty_nsuri_list.append('')    
    if None not in _empty_nsuri_list: __empty_nsuri_list.append(None)
  except:
    _empty_nsuri_list = [ None, '' ]
  def _find_attr(E, attr):
    for nsuri in _empty_nsuri_list:
        try:
            v = E.getAttributeNS(nsuri, attr)
            if v: return v
        except: pass
    return None

that's pretty horrible.

If PyXML 0.7 silently converts '' to None, then I can go back to
  _find_attr = lambda E, attr: E.getAttributeNS(None, attr) or \
	E.getAttributeNS('', attr)
which has a performance hit if the attribute is not found.

I am not sure which is better.
-- 
Zolera Systems, Your Key to Online Integrity
Securing Web services: XML, SOAP, Dig-sig, Encryption
http://www.zolera.com