Mercurial > libervia-backend
comparison src/tools/xml_tools.py @ 1819:c271087d2020
core (xml_tools): added a method to find all elements corresponding to criteria
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 22 Jan 2016 20:24:17 +0100 |
parents | 7e6342de71fb |
children | 29564cec913f |
comparison
equal
deleted
inserted
replaced
1818:7e6342de71fb | 1819:c271087d2020 |
---|---|
1393 data = [] | 1393 data = [] |
1394 for child in node.childNodes: | 1394 for child in node.childNodes: |
1395 if child.nodeType == child.TEXT_NODE: | 1395 if child.nodeType == child.TEXT_NODE: |
1396 data.append(child.wholeText) | 1396 data.append(child.wholeText) |
1397 return u"".join(data) | 1397 return u"".join(data) |
1398 | |
1399 def findAll(elt, names=None, namespaces=None): | |
1400 """Find child element at any depth matching criteria | |
1401 | |
1402 @param elt(domish.Element): top parent of the elements to find | |
1403 @param names(iterable, None): names to match | |
1404 None to accept every names | |
1405 @param namespace(unicode): URIs to match | |
1406 None to accept every namespaces | |
1407 """ | |
1408 | |
1409 for child in elt.elements(): | |
1410 if ((not names or child.name in names) and | |
1411 (not namespaces or child.uri in namespaces)): | |
1412 yield child | |
1413 for found in findAll(child, names): | |
1414 yield found |