_string = string
del string
+from xml.dom import HierarchyRequestErr
+
# localize the types, and allow support for Unicode values if available:
import types
_TupleType = types.TupleType
_debug = 0
_makeParentNodes = 1
debug = None
-
+ childNodeTypes = ()
+
def __init__(self):
self.childNodes = []
self.parentNode = None
return self.childNodes[-1]
def insertBefore(self, newChild, refChild):
+ if newChild.nodeType not in self.childNodeTypes:
+ raise HierarchyRequestErr, \
+ "%s cannot be child of %s" % (repr(newChild), repr(self) )
if newChild.parentNode is not None:
newChild.parentNode.removeChild(newChild)
if refChild is None:
return newChild
def appendChild(self, node):
+ if node.nodeType not in self.childNodeTypes:
+ raise HierarchyRequestErr, \
+ "%s cannot be child of %s" % (repr(node), repr(self) )
if node.parentNode is not None:
node.parentNode.removeChild(node)
if self.childNodes:
return node
def replaceChild(self, newChild, oldChild):
+ if newChild.nodeType not in self.childNodeTypes:
+ raise HierarchyRequestErr, \
+ "%s cannot be child of %s" % (repr(newChild), repr(self) )
if newChild.parentNode is not None:
newChild.parentNode.removeChild(newChild)
if newChild is oldChild:
nodeType = Node.ATTRIBUTE_NODE
attributes = None
ownerElement = None
-
+ childNodeTypes = (Node.TEXT_NODE, Node.ENTITY_REFERENCE_NODE)
+
def __init__(self, qName, namespaceURI="", localName=None, prefix=None):
# skip setattr for performance
d = self.__dict__
nodeType = Node.ELEMENT_NODE
nextSibling = None
previousSibling = None
-
+ childNodeTypes = (Node.ELEMENT_NODE, Node.PROCESSING_INSTRUCTION_NODE,
+ Node.COMMENT_NODE, Node.TEXT_NODE,
+ Node.CDATA_SECTION_NODE, Node.ENTITY_REFERENCE_NODE)
+
def __init__(self, tagName, namespaceURI="", prefix="",
localName=None):
Node.__init__(self)
nodeType = Node.COMMENT_NODE
nodeName = "#comment"
attributes = None
-
+ childNodeTypes = ()
+
def __init__(self, data):
Node.__init__(self)
self.data = self.nodeValue = data
class ProcessingInstruction(Node):
nodeType = Node.PROCESSING_INSTRUCTION_NODE
attributes = None
-
+ childNodeTypes = ()
+
def __init__(self, target, data):
Node.__init__(self)
self.target = self.nodeName = target
nodeType = Node.TEXT_NODE
nodeName = "#text"
attributes = None
-
+ childNodeTypes = ()
+
def __init__(self, data):
Node.__init__(self)
self.data = self.nodeValue = data
parentNode = None
implementation = DOMImplementation()
+ childNodeTypes = (Node.ELEMENT_NODE, Node.PROCESSING_INSTRUCTION_NODE,
+ Node.COMMENT_NODE, Node.DOCUMENT_TYPE_NODE)
def appendChild(self, node):
+ if node.nodeType not in self.childNodeTypes:
+ raise HierarchyRequestErr, \
+ "%s cannot be child of %s" % (repr(node), repr(self) )
if node.parentNode is not None:
node.parentNode.removeChild(node)