descendant

returns descendant of this element.

Source


def descendant(self):
    ret = pyNodeList()
    if self.has_child():
        children = self.children()
        if isinstance(children, pyNode):
            tmp = pyNodeList()
            tmp.append(children)
            children = tmp
        if isinstance(children, pyNodeList) and len(children) != 0:
            for ch in children:
                ret.append(ch)
                grand = ch.descendant()
                if isinstance(grand, pyNodeList) and len(grand) != 0:
                    ret.extend(grand)
                elif isinstance(grand, pyNode):
                    ret.append(grand)
    if len(ret) == 1: return ret[0]
    else: return ret