views:

564

answers:

2

Is there a way to find all nodes in a xml tree using cElementTree? The findall method works only for specified tags.

+1  A: 

You can use XPath paths on the findall method:

The 1.2 release supports simple element location paths. In its simplest form, a location path is one or more tag names, separated by slashes (/).

You can also use an asterisk (*) instead of a tag name, to match all elements at that level. For example, */subtag returns all subtag grandchildren.

An empty tag (//) is used to search on all levels of the tree, beneath the current level. The empty tag must always be followed by a tag name or an asterisk.

etree.findall('.//*')
Vinko Vrsalovic
+1  A: 

Have you looked at node.getiterator()?

S.Lott