Mercurial > libervia-backend
comparison src/tools/xml_tools.py @ 2108:70f23bc7859b
core (xml_tools): fixed findAll
- names and namespases arguments haven been inverted to be in the same order as for domish.Element.elements
- fixed bad copy of elements in recursions
- check if childrens are IElements
- namespaces and names can now be basestrings instead of iterables
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 03 Jan 2017 18:51:50 +0100 |
parents | c2fdee1bd908 |
children | 5defafc8ede6 |
comparison
equal
deleted
inserted
replaced
2107:2c31ddf633e5 | 2108:70f23bc7859b |
---|---|
1403 for child in node.childNodes: | 1403 for child in node.childNodes: |
1404 if child.nodeType == child.TEXT_NODE: | 1404 if child.nodeType == child.TEXT_NODE: |
1405 data.append(child.wholeText) | 1405 data.append(child.wholeText) |
1406 return u"".join(data) | 1406 return u"".join(data) |
1407 | 1407 |
1408 def findAll(elt, names=None, namespaces=None): | 1408 def findAll(elt, namespaces=None, names=None, ): |
1409 """Find child element at any depth matching criteria | 1409 """Find child element at any depth matching criteria |
1410 | 1410 |
1411 @param elt(domish.Element): top parent of the elements to find | 1411 @param elt(domish.Element): top parent of the elements to find |
1412 @param names(iterable, None): names to match | 1412 @param names(iterable[unicode], basestring, None): names to match |
1413 None to accept every names | 1413 None to accept every names |
1414 @param namespace(unicode): URIs to match | 1414 @param namespace(iterable[unicode], basestring, None): URIs to match |
1415 None to accept every namespaces | 1415 None to accept every namespaces |
1416 """ | 1416 @return ((G)domish.Element): found elements |
1417 """ | |
1418 if isinstance(namespaces, basestring): | |
1419 namespaces=tuple((namespaces,)) | |
1420 if isinstance(names, basestring): | |
1421 names=tuple((names,)) | |
1417 | 1422 |
1418 for child in elt.elements(): | 1423 for child in elt.elements(): |
1419 if ((not names or child.name in names) and | 1424 if (domish.IElement.providedBy(child) and |
1425 (not names or child.name in names) and | |
1420 (not namespaces or child.uri in namespaces)): | 1426 (not namespaces or child.uri in namespaces)): |
1421 yield child | 1427 yield child |
1422 for found in findAll(child, names): | 1428 for found in findAll(child, namespaces, names): |
1423 yield found | 1429 yield found |