* fix: getNode and getNodeText functions, now piksemel implementation
of xmlext works :) at least the tests say so (^_^)
This commit is contained in:
+18
-12
@@ -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."""
|
||||||
@@ -154,6 +160,11 @@ def addNode(node, tagpath, newnode = None, branch=True):
|
|||||||
return addTagPath(node, tags, newnode)
|
return addTagPath(node, tags, newnode)
|
||||||
|
|
||||||
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):
|
||||||
@@ -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)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user