""" narval.dom package
access readers, implementation and dom document via this module !!!
""" 

__revision__ = "$Id: __init__.py,v 1.13 2002/01/10 09:55:31 syt Exp $"

_IMPL = 'pDomlette' # cDomlette

if _IMPL == 'cDomlette':
    from Ft.Xml.cDomlette import RawExpatReader as DomReader, implementation
    def Document():
        d = implementation.createDocument(
            None, '', implementation.createDocumentType('test', 'test', ''))
        d.removeChild(d.firstChild)
        return d
else:
    try:
        from Ft.Xml.pDomlette import PyExpatReader as DomReader, Document,\
             implementation
    except Exception,e:
        from Ft.Lib.pDomlette import PyExpatReader as DomReader, Document,\
             implementation
    
from xml.dom import Node as _Node
DOCUMENT_NODE = _Node.DOCUMENT_NODE
DOCUMENT_FRAGMENT_NODE = _Node.DOCUMENT_FRAGMENT_NODE
ELEMENT_NODE = _Node.ELEMENT_NODE
TEXT_NODE = _Node.TEXT_NODE

## test dom implementation #####################################################
def _check_dom(dom):
    assert dom.namespaceURI or dom.namespaceURI is None,\
           'Empty NS uri != None for node %s (%s)' % (dom, dom.namespaceURI)
    assert dom.prefix or dom.prefix is None, \
           'Empty prefix != None for node %s (%s)' % (dom, dom.namespaceURI)
    if hasattr(dom, 'attributes') and dom.attributes:
        map(check_dom, dom.attributes.values())
    if hasattr(dom, 'childNodes') and dom.childNodes:
        map(check_dom, dom.childNodes)
        

