[lxml-dev] lxml.etree.parse doesn't take parser argument into account?
Hi, 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? This is lxml-1.3beta-py2.4-macosx-10.4-i386. -- Christian Zagrodnick gocept gmbh & co. kg · forsterstrasse 29 · 06112 halle/saale www.gocept.com · fon. +49 345 12298894 · fax. +49 345 12298891
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
On 2007-06-11 16:29:51 +0200, Stefan Behnel <stefan_ml@behnel.de> said:
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.
gaah... *takes blindfold off* Thanks Stefan. -- Christian Zagrodnick gocept gmbh & co. kg · forsterstrasse 29 · 06112 halle/saale www.gocept.com · fon. +49 345 12298894 · fax. +49 345 12298891
participants (2)
-
Christian Zagrodnick -
Stefan Behnel