在Python中,解析XML文档通常使用`ElementTree`模块。`ElementTree`提供了一种简单的方式来解析和操作XML数据。下面通过一个案例来说明如何使用Python的`ElementTree`来解析XML文档:
假设有一个名为`books.xml`的XML文件,内容如下:
 ```xml
 <library>
     <book>
         <title>Python Programming</title>
         <author>John Doe</author>
         <genre>Programming</genre>
         <price>29.99</price>
     </book>
     <book>
         <title>Data Science Handbook</title>
         <author>Jane Smith</author>
         <genre>Data Science</genre>
         <price>39.99</price>
     </book>
 </library>
 ```
接下来,我们将使用Python解析这个XML文件,并输出书籍信息:
```python
 import xml.etree.ElementTree as ET
# 加载XML文件
 tree = ET.parse('books.xml')
 root = tree.getroot()
# 遍历XML数据并输出书籍信息
 for book in root.findall('book'):
     title = book.find('title').text
     author = book.find('author').text
     genre = book.find('genre').text
     price = book.find('price').text
    print(f"Title: {title}")
     print(f"Author: {author}")
     print(f"Genre: {genre}")
     print(f"Price: {price}")
     print()
```
运行以上代码将输出每本书籍的标题、作者、类型和价格信息。在这个案例中,我们首先使用`ET.parse()`方法加载XML文件,然后通过`getroot()`方法获取根元素。接着使用`findall()`方法找到所有`book`元素,并通过`find()`方法获取各个子元素的文本内容,最后输出书籍信息。
通过这个案例,展示了如何使用Python的`ElementTree`模块来解析XML文档并提取其中的信息。在实际应用中,可以根据XML文档的结构和需求进行更复杂的解析和处理,以满足具体的业务需求。