[lxml-dev] find/findall not accepting qnames?

I find it surprising that find & findall do not accept QName objects in lxml, and instead require a manual cast to string, like so: etree.XML( '<a><ns0:b xmlns:ns0="http://test"/></a>' ).find( str( etree.QName( 'http://test', 'b' ) ) ) ElementTree appears to accept QNames transparently, in my limited testing. I haven't tested with earlier revisions, but after tracking down a couple of bugs related to this, is this a change in behavior in recent (1.1) lxml versions? -- John Krukoff <jkrukoff@ltgc.com> Land Title Guarantee Company

John Krukoff wrote:
I find it surprising that find & findall do not accept QName objects in lxml, and instead require a manual cast to string, like so:
etree.XML( '<a><ns0:b xmlns:ns0="http://test"/></a>' ).find( str( etree.QName( 'http://test', 'b' ) ) )
ElementTree appears to accept QNames transparently, in my limited testing.
I find it surprising that it does, though. Not sure that's intentional ;-) </F>

Hi, John Krukoff wrote:
I find it surprising that find & findall do not accept QName objects in lxml
True, that's about the only place where we do not parse the input ourselves but hand it to the ElementPath module of ElementTree. All other places use the same function for parsing tag names, so that makes QNames completely transparent in lxml. I agree that this is unexpected behaviour and since we accept QNames in loads of other places, we should make it a special case if a QName is passed as path to find*(). After all, it's a common use case to look for a specific tag instead of a path. BTW, using getiterator(tag) for this purpose should be a bit faster. Stefan
participants (3)
-
Fredrik Lundh
-
John Krukoff
-
Stefan Behnel