[lxml-dev] Element children not right?
Mike Meyer
mwm-keyword-lxml.9112b8 at mired.org
Sat Jul 14 10:09:37 CEST 2007
I think I have a very, very basic bug here:
>>> from sys import version
>>> version
'2.5.1 (r251:54863, May 15 2007, 15:31:37) \n[GCC 3.4.6 [FreeBSD] 20060305]'
>>> from lxml import etree
>>> etree.LXML_VERSION
(1, 3, 2, 0)
>>> etree.LIBXML_VERSION
(2, 6, 29)
>>> etree.LIBXSLT_VERSION
(1, 1, 21)
>>> d = etree.parse('/home/mwm/.plpwmrc.xml')
>>> n = d.find('namemenu')
>>> [el for el in n]
[<Element getapp at 7f1e10>, <Element getapp at 8aa418>, <!-- Damn Firefox doesn't set the title properly when running tabbed, just
uses "firefox-bin". So we try both cases. -->, <Element getapp at 8aa470>, <Element getapp at 8aa4c8>, <Element getapp at 926ec0>, <Element getapp at 926f18>, <Element getapp at 926f70>, <Element getapp at 926fc8>, <Element run at 977b50>, <Element getapp at 97d4c8>]
>>> from xml.etree.ElementTree import parse
>>> d2 = parse('/home/mwm/.plpwmrc.xml')
>>> n2 = d2.find('namemenu')
>>> [el for el in n2]
[<Element getapp at 9845a8>, <Element getapp at 9845f0>, <Element getapp at 984638>, <Element getapp at 984680>, <Element getapp at 9846c8>, <Element getapp at 984710>, <Element getapp at 984758>, <Element getapp at 9847a0>, <Element run at 9847e8>, <Element getapp at 984830>]
Note that the original ElementTree implementation only returns
children that are *elements*, whereas the lxml version returns all
the children. This makes life much more interesting, especially as
there isn't an obvious method for checking whether or not the node
value is actually an element.
<mike
--
Mike Meyer <mwm at mired.org> http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.
More information about the lxml-dev
mailing list