[lxml-dev] lxml.etree.parse doesn't take parser argument into account?
Stefan Behnel
stefan_ml at behnel.de
Mon Jun 11 16:29:51 CEST 2007
Hi,
Christian Zagrodnick wrote:
> maybe I'm doning something very wrong here. Regarding the following:
>
> In [1]:import StringIO
>
> In [2]:import lxml.etree
>
> In [3]:import lxml.objectify
>
> In [4]:parser = lxml.etree.XMLParser()
>
> In
> [5]:parser.setElementClassLookup(lxml.objectify.ObjectifyElementClassLookup())
>
> In
>
> [6]:lxml.etree.parse(StringIO.StringIO("<a/>"), parser)
> Out[6]:<etree._ElementTree object at 0x1450e40>
>
>
> I would have expected to get an objectified element out of the parse
> call. What am I missing here? Or is this a bug?
As your example shows, parse() returns an ElementTree object, not an Element.
http://effbot.org/zone/element.htm#reading-and-writing-xml-files
If you want the root Element object, call the "getroot()" method on the result
tree.
Stefan
More information about the lxml-dev
mailing list