core (xml_tools): added a method to find all elements corresponding to criteria
This commit is contained in:
parent
6c11191230
commit
99894bd6f2
1 changed files with 17 additions and 0 deletions
|
|
@ -1395,3 +1395,20 @@ def getText(node):
|
|||
if child.nodeType == child.TEXT_NODE:
|
||||
data.append(child.wholeText)
|
||||
return u"".join(data)
|
||||
|
||||
def findAll(elt, names=None, namespaces=None):
|
||||
"""Find child element at any depth matching criteria
|
||||
|
||||
@param elt(domish.Element): top parent of the elements to find
|
||||
@param names(iterable, None): names to match
|
||||
None to accept every names
|
||||
@param namespace(unicode): URIs to match
|
||||
None to accept every namespaces
|
||||
"""
|
||||
|
||||
for child in elt.elements():
|
||||
if ((not names or child.name in names) and
|
||||
(not namespaces or child.uri in namespaces)):
|
||||
yield child
|
||||
for found in findAll(child, names):
|
||||
yield found
|
||||
|
|
|
|||
Loading…
Reference in a new issue