What are we learning in this chapter?
In Part I, we looked at some of Python’s built-in XML parsers. In this chapter, we will look at the fun third-party package, lxml from codespeak. It uses the ElementTree API, among other things. The lxml package has XPath and XSLT support, includes an API for SAX and a C-level API for compatibility with C/Pyrex modules. Here is what we will cover:
- How to Parse XML with lxml
- A Refactoring example
- How to Parse XML with lxml.objectify
- How to Create XML with lxml.objectify
For this chapter, we will use the examples from the minidom parsing example and see how to parse those with lxml. Here’s an XML example from a program that was written for keeping track of appointments:
Get hands-on with 1400+ tech skills courses.