On 7 Mar 2026, at 0:21, Martin Mueller wrote:
Hi Martin,
> But something like
>
> for el in div.iter('*'):
> if len(el) < 4:
> etree.strip_tags(el, tei + 'hi')
>
> does not work. Is it not possible to specify constraints on the strip_tags
> function or do I not know what I am doing?
I've never worked with this so take my advice with a pinch of salt, but it
looks like you might be the victim of one of Python's most common gotchas:
changing an iterator while you loop over it. I think this may be why Jens
suggests you use an xpath expression which should produce a stable list of
elements to handle.
To see what's happening, I'd suggest you add some debug code that tells you
whether you're finding the right tags and what happens afterwards. I'd also
note, that you might prefer to use iterparse with xmlfile to create a new tree
over which you have more control.
Charlie
--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Sengelsweg 34
Düsseldorf
D- 40489
Tel: +49-203-3925-0390
Mobile: +49-178-782-6226
_______________________________________________
lxml - The Python XML Toolkit mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/lxml.python.org
Member address: [email protected]