On a side note, you may also use node \ "_" to get all child elements, but it won't contain text nodes.

Or you may use node.descendant or node.descendant_or_self to have a List of all the descendants in DFS order without writing the traversal yourself. You have to filter out the "empty" nodes from the descendants as well: filterEmptyNodes(node.descendant) or filterEmptyNodes(node.descendant_or_self)