Going Further With lxml
Discover how to leverage the lxml library in Python 3 to parse large XML documents efficiently, utilize a fully compatible ElementTree API, and implement advanced XPath 1.0 queries. Learn to handle namespaces and attributes to perform complex XML data extraction and querying.
We'll cover the following...
lxml is an open source third-party library that builds on the popular libxml2 parser. It provides a 100% compatible ElementTree api, then extends it with full XPath 1.0 support and a few other niceties. There are installers available for Windows; Linux users should always try to use distribution-specific tools like yum or apt-get to install precompiled binaries from their repositories. Otherwise you’ll need to install lxml manually.
① Once imported, lxml provides the same api as the built-in ElementTree library.
② parse() function: same as ElementTree.
③ getroot() method: also the same. ...