擅长:python、mysql、java
<p>您可以使用<code>lxml</code>库来解析任何xml内容。这个库比标准的<code>xml</code>库更好,因为它允许您在必要时获取xml文档的名称空间(在您的案例中不需要)。你知道吗</p>
<pre><code>from lxml import etree
tree = etree.parse(path_to_xml_file)
root = tree.getroot()
for children in root.getchildren():
print (children.tag)
for child in children:
print(child.tag, child.text)
</code></pre>
<p>有关如何访问xml文件的各个部分并递归查找所有子元素的详细信息,请参阅文档<a href="https://docs.python.org/2/library/xml.etree.elementtree.html" rel="nofollow noreferrer">here</a>。。本文档适用于标准<code>xml</code>库,但由于<code>lxml</code>构建在<code>xml</code>之上,因此<code>lxml</code>库也支持此文档。你知道吗</p>