w3c document object model implementation for python the python mapping of the document object model is documented in the python library reference in the section on the xml dom package this package contains the following modules minidom a simple implementation of the level 1 dom with namespace support added based on the level 2 specification and other minor level 2 functionality pulldom dom builder supporting ondemand treebuilding for selected subtrees of the document class giving the nodetype constants slots dom implementations may use this as a base class for their own node implementations if they don t the constants defined here should still be used as the canonical definitions as they match the values given in the w3c recommendation client code can safely refer to these values in all tests of node nodetype values elementnode 1 attributenode 2 textnode 3 cdatasectionnode 4 entityreferencenode 5 entitynode 6 processinginstructionnode 7 commentnode 8 documentnode 9 documenttypenode 10 documentfragmentnode 11 notationnode 12 exceptioncode indexsizeerr 1 domstringsizeerr 2 hierarchyrequesterr 3 wrongdocumenterr 4 invalidcharactererr 5 nodataallowederr 6 nomodificationallowederr 7 notfounderr 8 notsupportederr 9 inuseattributeerr 10 invalidstateerr 11 syntaxerr 12 invalidmodificationerr 13 namespaceerr 14 invalidaccesserr 15 validationerr 16 class domexceptionexception class giving the operation constants for userdatahandler handle based on dom level 3 wd 9 april 2002 nodecloned 1 nodeimported 2 nodedeleted 3 noderenamed 4 xmlnamespace http www w3 orgxml1998namespace xmlnsnamespace http www w3 org2000xmlns xhtmlnamespace http www w3 org1999xhtml emptynamespace none emptyprefix none from domreg import getdomimplementation registerdomimplementation class giving the nodetype constants dom implementations may use this as a base class for their own node implementations if they don t the constants defined here should still be used as the canonical definitions as they match the values given in the w3c recommendation client code can safely refer to these values in all tests of node nodetype values exceptioncode abstract base class for dom exceptions exceptions with specific codes are specializations of this class class giving the operation constants for userdatahandler handle based on dom level 3 wd 9 april 2002
class Node:
    
    __slots__ = ()

    
    
    
    
    
    

    ELEMENT_NODE                = 1
    ATTRIBUTE_NODE              = 2
    TEXT_NODE                   = 3
    CDATA_SECTION_NODE          = 4
    ENTITY_REFERENCE_NODE       = 5
    ENTITY_NODE                 = 6
    PROCESSING_INSTRUCTION_NODE = 7
    COMMENT_NODE                = 8
    DOCUMENT_NODE               = 9
    DOCUMENT_TYPE_NODE          = 10
    DOCUMENT_FRAGMENT_NODE      = 11
    NOTATION_NODE               = 12



INDEX_SIZE_ERR                 = 1
DOMSTRING_SIZE_ERR             = 2
HIERARCHY_REQUEST_ERR          = 3
WRONG_DOCUMENT_ERR             = 4
INVALID_CHARACTER_ERR          = 5
NO_DATA_ALLOWED_ERR            = 6
NO_MODIFICATION_ALLOWED_ERR    = 7
NOT_FOUND_ERR                  = 8
NOT_SUPPORTED_ERR              = 9
INUSE_ATTRIBUTE_ERR            = 10
INVALID_STATE_ERR              = 11
SYNTAX_ERR                     = 12
INVALID_MODIFICATION_ERR       = 13
NAMESPACE_ERR                  = 14
INVALID_ACCESS_ERR             = 15
VALIDATION_ERR                 = 16


class DOMException(Exception):
    

    def __init__(self, *args, **kw):
        if self.__class__ is DOMException:
            raise RuntimeError(
                "DOMException should not be instantiated directly")
        Exception.__init__(self, *args, **kw)

    def _get_code(self):
        return self.code


class IndexSizeErr(DOMException):
    code = INDEX_SIZE_ERR

class DomstringSizeErr(DOMException):
    code = DOMSTRING_SIZE_ERR

class HierarchyRequestErr(DOMException):
    code = HIERARCHY_REQUEST_ERR

class WrongDocumentErr(DOMException):
    code = WRONG_DOCUMENT_ERR

class InvalidCharacterErr(DOMException):
    code = INVALID_CHARACTER_ERR

class NoDataAllowedErr(DOMException):
    code = NO_DATA_ALLOWED_ERR

class NoModificationAllowedErr(DOMException):
    code = NO_MODIFICATION_ALLOWED_ERR

class NotFoundErr(DOMException):
    code = NOT_FOUND_ERR

class NotSupportedErr(DOMException):
    code = NOT_SUPPORTED_ERR

class InuseAttributeErr(DOMException):
    code = INUSE_ATTRIBUTE_ERR

class InvalidStateErr(DOMException):
    code = INVALID_STATE_ERR

class SyntaxErr(DOMException):
    code = SYNTAX_ERR

class InvalidModificationErr(DOMException):
    code = INVALID_MODIFICATION_ERR

class NamespaceErr(DOMException):
    code = NAMESPACE_ERR

class InvalidAccessErr(DOMException):
    code = INVALID_ACCESS_ERR

class ValidationErr(DOMException):
    code = VALIDATION_ERR

class UserDataHandler:
    

    

    NODE_CLONED   = 1
    NODE_IMPORTED = 2
    NODE_DELETED  = 3
    NODE_RENAMED  = 4

XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace"
XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/"
XHTML_NAMESPACE = "http://www.w3.org/1999/xhtml"
EMPTY_NAMESPACE = None
EMPTY_PREFIX = None

from .domreg import getDOMImplementation, registerDOMImplementation