On Thu, Nov 23, 2017 at 6:18 AM, Charlie Clark <charlie.clark@clark-consulting.eu> wrote:
Am .11.2017, 14:55 Uhr, schrieb Chris Jerdonek <chris.jerdonek@gmail.com>:
It would suffice to be able to specify the starting point for the iterator `root.iter(*tags)` -- in other words to start it midway through. Is there a way to do that that doesn't involve, say, first iterating through the first elements of `root.iter(*tags)`?
Depends on how you define efficiency… You can always use XPath to access specific elements or just `find(fully_qualified_tagname)`. However, if it's a large file you might want to keep memory use as low as possible and use the event-based `iterparse()` approach.
Thanks, Charlie. But in my question you can assume the document is already parsed and the starting element is already accessed. So the question is: does lxml provide a way to find the element after that in the tree? It would be nice to be able to do something like-- next(root.iter(*tags)[element:]) # first element strictly after "element" --Chris
lxml adds some comfort to the etree.iterparse function by letting you pass in a list of the tags you're interested in.
Charlie -- Charlie Clark Managing Director Clark Consulting & Research German Office Kronenstr. 27a Düsseldorf D- 40217 Tel: +49-211-600-3657 Mobile: +49-178-782-6226 _________________________________________________________________ Mailing list for the lxml Python XML toolkit - http://lxml.de/ lxml@lxml.de https://mailman-mail5.webfaction.com/listinfo/lxml