Find all nodes from an XML using cElementTree

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

Answers


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('.//*')

Need Your Help

Best way to rename MainWindow

c# wpf visual-studio visual-studio-2010 xaml

In Visual Studio 2010, if I create a new project that is a WPF Application, the MainWindow subclass of Window is provided as a default first window. The steps I've been taking to rename MainWindow ...

Magento Custom Module database query

magento

I have written a module to add my own events, and in the home page i would like to show only latest events. So in that case i have to add order by to query but i couldnot do that, it always throws ...