1.1 --- a/__init__.py Sun Oct 05 22:57:09 2003 +0000
1.2 +++ b/__init__.py Sun Oct 05 23:41:59 2003 +0000
1.3 @@ -15,16 +15,16 @@
1.4 self.node = node
1.5
1.6 def getNamedItem(self, name):
1.7 - pass
1.8 + return self.node.getAttributeNode(name)
1.9
1.10 def getNamedItemNS(self, ns, localName):
1.11 - pass
1.12 + return self.node.getAttributeNodeNS(ns, localName)
1.13
1.14 def setNamedItem(self, node):
1.15 - pass
1.16 + self.node.setAttributeNode(node.name, node)
1.17
1.18 def setNamedItemNS(self, node):
1.19 - pass
1.20 + self.node.setAttributeNodeNS(node.namespaceURI, node.localName, node)
1.21
1.22 def __getitem__(self, name):
1.23 pass
1.24 @@ -108,11 +108,10 @@
1.25 # NOTE: Consider a generator instead.
1.26
1.27 child_nodes = []
1.28 - child_node = self._node.children
1.29 - while child_node is not None:
1.30 - child_nodes.append(
1.31 - self.__class__(child_node))
1.32 - child_node = child_node.next
1.33 + _node = self._node.children
1.34 + while _node is not None:
1.35 + child_nodes.append(Node(_node))
1.36 + _node = _node.next
1.37 return child_nodes
1.38
1.39 def _attributes(self):
1.40 @@ -161,7 +160,10 @@
1.41 return self._node.name
1.42
1.43 def _parentNode(self):
1.44 - return self._node.parent
1.45 + if self.nodeType == xml.dom.Node.DOCUMENT_NODE:
1.46 + return None
1.47 + else:
1.48 + return Node(self._node.parent)
1.49
1.50 def getAttributeNS(self, ns, localName):
1.51 return self._node.nsProp(localName, ns)
2.1 --- a/test.py Sun Oct 05 22:57:09 2003 +0000
2.2 +++ b/test.py Sun Oct 05 23:41:59 2003 +0000
2.3 @@ -2,6 +2,8 @@
2.4
2.5 import libxml2dom
2.6 import libxml2
2.7 +from xml.dom.ext import PrettyPrint
2.8 +
2.9 #doc = libxml2.parseFile("XMLTools2/examples/zoo/zoo_schema.xml")
2.10 doc = libxml2.parseDoc("""<?xml version="1.0" encoding="iso-8859-15"?>
2.11 <schema xmlns="http://www.boddie.org.uk/ns/xmltools/model"
2.12 @@ -16,7 +18,7 @@
2.13 print d.childNodes[0].childNodes[1]._node.nsProp("table", 'http://www.boddie.org.uk/ns/xmltools/database')
2.14 print doc.children.children.next.nsProp("table", 'http://www.boddie.org.uk/ns/xmltools/database')
2.15 # This works only with an appropriate patch to libxml2 2.5.7:
2.16 -print d.childNodes[0].childNodes[1].attributes[1]._node.ns()
2.17 +print d.childNodes[0].childNodes[1].attributes.values()[1]._node.ns()
2.18 # Equivalent to:
2.19 print d.childNodes[0].childNodes[1]._node.properties.next.ns()
2.20 print doc.children.children.next.properties.next.ns()