1.1 --- a/__init__.py Sun Oct 05 21:53:02 2003 +0000
1.2 +++ b/__init__.py Sun Oct 05 22:57:09 2003 +0000
1.3 @@ -72,6 +72,12 @@
1.4 self.nodeType = nodeType
1.5 self.prefix, self.localName = _get_prefix_and_localName(self.name)
1.6
1.7 +class TemporaryText(object):
1.8 + def __init__(self, _text):
1.9 + self.ns = self.name = self.prefix = self.localName = None
1.10 + self.nodeType = xml.dom.Node.TEXT_NODE
1.11 + self._text = _text
1.12 +
1.13 class Node(object):
1.14
1.15 _nodeTypes = {
1.16 @@ -200,6 +206,9 @@
1.17 def createAttribute(self, name):
1.18 return TemporaryNode(ns, name, xml.dom.Node.ATTRIBUTE_NODE)
1.19
1.20 + def createTextNode(self, value):
1.21 + return TemporaryText(self._node.doc.newDocText(value))
1.22 +
1.23 def _add_node(self, tmp):
1.24 if tmp.ns is not None:
1.25 if tmp.nodeType == xml.dom.Node.ELEMENT_NODE:
1.26 @@ -223,20 +232,30 @@
1.27 return _child
1.28
1.29 def insertBefore(self, tmp, oldNode):
1.30 - _child = self._add_node(tmp)
1.31 - _child.unlinkNode()
1.32 + if tmp.nodeType == xml.dom.Node.TEXT_NODE:
1.33 + _child = tmp._text
1.34 + else:
1.35 + _child = self._add_node(tmp)
1.36 + _child.unlinkNode()
1.37 return Node(oldNode._node.addPrevSibling(_child))
1.38
1.39 def replaceChild(self, tmp, oldNode):
1.40 - _child = self._add_node(tmp)
1.41 - _child.unlinkNode()
1.42 + if tmp.nodeType == xml.dom.Node.TEXT_NODE:
1.43 + _child = tmp._text
1.44 + else:
1.45 + _child = self._add_node(tmp)
1.46 + _child.unlinkNode()
1.47 return Node(oldNode._node.replaceNode(_child))
1.48
1.49 def appendChild(self, tmp):
1.50 - return Node(self._add_node(tmp))
1.51 + if tmp.nodeType == xml.dom.Node.TEXT_NODE:
1.52 + _child = self._node.addChild(tmp._text)
1.53 + else:
1.54 + _child = self._add_node(tmp)
1.55 + return Node(_child)
1.56
1.57 #doctype = property(_doctype)
1.58 - #ownerElement = property(_ownerElement)
1.59 + #ownerElement defined in __init__
1.60 ownerDocument = property(_ownerDocument)
1.61 childNodes = property(_childNodes)
1.62 value = data = nodeValue = property(_nodeValue)