From c8f341ca622397b0634942f89b3631655604c7f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Wed, 9 Nov 2005 21:58:06 +0000 Subject: [PATCH] * fix: getNode and getNodeText functions, now piksemel implementation of xmlext works :) at least the tests say so (^_^) --- pisi/xml/xmlextpiks.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/pisi/xml/xmlextpiks.py b/pisi/xml/xmlextpiks.py index ae5dd248..c4eca52e 100644 --- a/pisi/xml/xmlextpiks.py +++ b/pisi/xml/xmlextpiks.py @@ -54,9 +54,9 @@ def getNodeText(node, tagpath = ""): return None except AttributeError: # no node by that name return None - if child.nodeType == CDATA: #FIXME: ??? TEXT type? - # in any case, strip whitespaces... - return child.getTagData().strip() + if child.type() == CDATA: #FIXME: ??? TEXT type? + # in any case, strip whitespaces... :/ you don't like it? + return child.data().strip() else: raise XmlError(_("getNodeText: Expected text node, got something else!")) @@ -76,10 +76,16 @@ def getNode(node, tagpath): # iterative code to search for the path for tag in tags: - for child in node: - if child.type == TAG and child.name == tag: - return child - return None + currentNode = None + for child in node.tags(): + if child.name() == tag: + currentNode = child + break + if not currentNode: + return None + else: + node = currentNode + return currentNode def getAllNodes(node, tagPath): """retrieve all nodes that match a given tag path.""" @@ -154,6 +160,11 @@ def addNode(node, tagpath, newnode = None, branch=True): return addTagPath(node, tags, newnode) return node + +def addText(node, tagPath, text, branch = True): + node = addNode(node, tagPath, branch = branch) + return node.appendData(text) + # cannot be implemented with piksemel #def newNode(node, tag): @@ -162,8 +173,3 @@ def addNode(node, tagpath, newnode = None, branch=True): # cannot be implemented with piksemel :( #def newTextNode(node, text): # return Node(text) - - -def addText(node, tagPath, text, branch = True): - node = addNode(node, tagPath, branch = branch) - return node.appendData(text)