Suppose you want to extract some information from an XML document. Here's the general procedure:
You'll need to import the lxml package. Here is one way
to do it:
from lxml import etree
Typically your XML document will be in a file
somewhere. Suppose your file is named test.xml; to read the document, you might
say something like:
doc = etree.parse ( 'test.xml' )
The returned value doc is an instance of
the ElementTree class that represents
your XML document in tree form.
Once you have your document in this form, refer to
Section 7, “class ElementTree: A complete XML document” to learn how to
navigate around the tree and extract the various parts
of its structure.
For other methods of creating an ElementTree, refer to Section 6, “Features of the etree module”.