# HG changeset patch # User Goffi # Date 1453490657 -3600 # Node ID c271087d202076ea7d8541c6b3167b7e03f10fba # Parent 7e6342de71fb96fb64b70217730b4183c4703320 core (xml_tools): added a method to find all elements corresponding to criteria diff -r 7e6342de71fb -r c271087d2020 src/tools/xml_tools.py --- a/src/tools/xml_tools.py Fri Jan 22 20:24:17 2016 +0100 +++ b/src/tools/xml_tools.py Fri Jan 22 20:24:17 2016 +0100 @@ -1395,3 +1395,20 @@ 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