The lxml.etree Tutorial | Python etree html
ThisisatutorialonXMLprocessingwithlxml.etree.ItbrieflyoverviewsthemainconceptsoftheElementTreeAPI[1],andsomesimpleenhancementsthatmakeyourlifeasaprogrammereasier.IfyourcodeonlyusestheElementTreeAPIanddoesnotrelyonanyfunctionalitythatisspecifictolxml.etree,youcanalsouse(anypartof)thefollowingimportchainasafall-backtotheoriginalElementTree:Toaidinwritingportablecode,thistutorialmakesitclearintheexampleswhichpartofthepresentedAPIisanextensionoflxml.etreeovertheoriginalElementTreeAPI[2],asdefine...
This is a tutorial on XML processing with lxml.etree. It briefly overviews the main concepts of the ElementTree API[1], and some simple enhancements that make your life as a programmer easier.
If your code only uses the ElementTree API and does not rely on any functionality that is specific to lxml.etree, you can also use (any part of) the following import chain as a fall-back to the original ElementTree:
To aid in writing portable code, this tutorial makes it clear in the examples which part of the presented API is an extension of lxml.etree over the original ElementTree API[2], as defined by Fredrik Lundhs ElementTree library[3].
An Element is the main container object for the ElementTree API. Most of the XML tree functionality is accessed through this class. Elements are easily created through the Element factory:
>>> root = etree.Element("root")The XML tag name of elements is accessed through the tag property:
Elements are organis...