Hi Stefan, Am I right that there is a bit of asymmetry in the way that multiple tags are handled by iterwalk(), as compared to, say, methods like _Element.iter()? Whereas _Element.iter()'s signature is-- iter(self, tag=None, *tags) iterwalk()'s signature is-- iterwalk(self, element_or_tree, events=("end",), tag=None), It doesn't seem to be documented that iterwalk() accepts more than one tag, but empirically I found that a tuple of tags can be passed as the tag argument to iterwalk(). Is that intentional? Thanks, --Chris On Fri, Nov 24, 2017 at 9:08 PM, Chris Jerdonek <chris.jerdonek@gmail.com> wrote:
Thanks. I didn't know about iterwalk() with its skip_subtree(). I'll give it a shot.
--Chris
On Fri, Nov 24, 2017 at 5:29 AM, Stefan Behnel <stefan_ml@behnel.de> wrote:
Chris Jerdonek schrieb am 24.11.2017 um 10:31:
On Fri, Nov 24, 2017 at 12:42 AM, Stefan Behnel wrote:
Chris Jerdonek schrieb am 23.11.2017 um 14:55:
I have a seemingly simple lxml.etree use case, but the API doesn't seem to support it.
Say I have an Element "root" at the root of a tree, and say I have an element "element" inside the tree. Is there an efficient way to get the element **after** "element" (in document order), and matching given tags?
Your use case isn't clear to me. How do you get at that element? Could you provide some more details?
Thanks. I'll provide more details.
Given a tree, I want to perform some processing on every subtree in the tree having certain properties. The properties are (1) that the root element of the subtree is one of a number of tags, say "a" and "b", and (2) the root doesn't have any ancestors with those tags. So these can be thought of as the "maximal" subtrees with a root having tag "a" or "b".
This sounds like iterwalk() might solve your problem.
http://lxml.de/parsing.html#iterparse-and-iterwalk
Stefan _________________________________________________________________ Mailing list for the lxml Python XML toolkit - http://lxml.de/ lxml@lxml.de https://mailman-mail5.webfaction.com/listinfo/lxml