What is the difference between lxml.etree._ElementTree and lxml.etree._Element?

Hi, I can not tell the difference between lxml.etree._ElementTree and lxml.etree._Element. Could anybody explain what is the difference between them? Thanks. $ ./main.py bar <<< '<foo><x><bar>abc</bar></x><bar>xyz</bar></foo>' <type 'lxml.etree._ElementTree'> ['<bar>xyz</bar>'] <type 'lxml.etree._Element'> ['<bar>xyz</bar>'] $ cat main.py #!/usr/bin/env python # vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8: from lxml import etree import sys tree = etree.parse(sys.stdin) print type(tree) print [etree.tostring(x) for x in tree.iterfind(sys.argv[1])] r = tree.xpath('/foo') print type(r[0]) print [etree.tostring(x) for x in r[0].iterfind(sys.argv[1])] -- Regards, Peng

Hi, Am Tue, 17 Apr 2018 23:20:07 -0500 schrieb Peng Yu <pengyu.ut@gmail.com>:
I can not tell the difference between lxml.etree._ElementTree and lxml.etree._Element. Could anybody explain what is the difference between them? Thanks.
Read http://lxml.de/tutorial.html#the-element-class and http://lxml.de/tutorial.html#the-elementtree-class This should help to explain the difference. :) -- Gruß/Regards, Thomas Schraitle
participants (2)
-
Peng Yu
-
Thomas Schraitle