* fix: getNode and getNodeText functions, now piksemel implementation

of xmlext works :) at least the tests say so (^_^)
This commit is contained in:
Eray Özkural
2005-11-09 21:58:06 +00:00
parent a810f98d01
commit c8f341ca62
+18 -12
View File
@@ -54,9 +54,9 @@ def getNodeText(node, tagpath = ""):
return None return None
except AttributeError: # no node by that name except AttributeError: # no node by that name
return None return None
if child.nodeType == CDATA: #FIXME: ??? TEXT type? if child.type() == CDATA: #FIXME: ??? TEXT type?
# in any case, strip whitespaces... # in any case, strip whitespaces... :/ you don't like it?
return child.getTagData().strip() return child.data().strip()
else: else:
raise XmlError(_("getNodeText: Expected text node, got something 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 # iterative code to search for the path
for tag in tags: for tag in tags:
for child in node: currentNode = None
if child.type == TAG and child.name == tag: for child in node.tags():
return child if child.name() == tag:
return None currentNode = child
break
if not currentNode:
return None
else:
node = currentNode
return currentNode
def getAllNodes(node, tagPath): def getAllNodes(node, tagPath):
"""retrieve all nodes that match a given tag path.""" """retrieve all nodes that match a given tag path."""
@@ -155,6 +161,11 @@ def addNode(node, tagpath, newnode = None, branch=True):
return node return node
def addText(node, tagPath, text, branch = True):
node = addNode(node, tagPath, branch = branch)
return node.appendData(text)
# cannot be implemented with piksemel # cannot be implemented with piksemel
#def newNode(node, tag): #def newNode(node, tag):
# return Node(tag) # return Node(tag)
@@ -162,8 +173,3 @@ def addNode(node, tagpath, newnode = None, branch=True):
# cannot be implemented with piksemel :( # cannot be implemented with piksemel :(
#def newTextNode(node, text): #def newTextNode(node, text):
# return Node(text) # return Node(text)
def addText(node, tagPath, text, branch = True):
node = addNode(node, tagPath, branch = branch)
return node.appendData(text)