# HG changeset patch # User paulb # Date 1065478260 0 # Node ID c8b5119e842a3b48c567d6a489953982c0c04bc0 # Parent 0cc134cda8ec7cd9ba3a9629ec948e1386af521b [project @ 2003-10-06 22:11:00 by paulb] Changed text node creation to use libxml2 utility functions, eliminating the TemporaryText class. Updated the test program to use a utility function for parsing. diff -r 0cc134cda8ec -r c8b5119e842a __init__.py --- a/__init__.py Mon Oct 06 21:59:05 2003 +0000 +++ b/__init__.py Mon Oct 06 22:11:00 2003 +0000 @@ -77,12 +77,6 @@ self.nodeType = nodeType self.prefix, self.localName = _get_prefix_and_localName(self.name) -class TemporaryText(object): - def __init__(self, _text): - self.ns = self.name = self.prefix = self.localName = None - self.nodeType = xml.dom.Node.TEXT_NODE - self._text = _text - class Node(object): _nodeTypes = { @@ -237,7 +231,7 @@ return TemporaryNode(ns, name, xml.dom.Node.ATTRIBUTE_NODE) def createTextNode(self, value): - return TemporaryText(self._node.doc.newDocText(value)) + return Node(libxml2.newText(value)) def _add_node(self, tmp): if tmp.nodeType == xml.dom.Node.ATTRIBUTE_NODE: @@ -277,7 +271,7 @@ def insertBefore(self, tmp, oldNode): if tmp.nodeType == xml.dom.Node.TEXT_NODE: - _child = tmp._text + _child = tmp._node elif tmp.nodeType == xml.dom.Node.ELEMENT_NODE: _child = tmp._node else: @@ -287,7 +281,7 @@ def replaceChild(self, tmp, oldNode): if tmp.nodeType == xml.dom.Node.TEXT_NODE: - _child = tmp._text + _child = tmp._node elif tmp.nodeType == xml.dom.Node.ELEMENT_NODE: _child = tmp._node else: @@ -297,7 +291,7 @@ def appendChild(self, tmp): if tmp.nodeType == xml.dom.Node.TEXT_NODE: - _child = self._node.addChild(tmp._text) + _child = self._node.addChild(tmp._node) elif tmp.nodeType == xml.dom.Node.ELEMENT_NODE: _child = self._node.addChild(tmp._node) else: diff -r 0cc134cda8ec -r c8b5119e842a test.py --- a/test.py Mon Oct 06 21:59:05 2003 +0000 +++ b/test.py Mon Oct 06 22:11:00 2003 +0000 @@ -1,11 +1,10 @@ #!/usr/bin/env python import libxml2dom -import libxml2 from xml.dom.ext import PrettyPrint import sys -doc = libxml2.parseFile(sys.argv[1]) +d = libxml2dom.parse(sys.argv[1]) #doc = libxml2.parseDoc(""" # #""") -d = libxml2dom.Node(doc) PrettyPrint(d) # vim: tabstop=4 expandtab shiftwidth=4