擅长:python、mysql、java
<p>出于安全原因,您应该避免使用<code>exec</code>,而且您可能应该将字段值保留在<code>dict</code>或类似的结构中。最好让Python库完成整个解析。例如,使用<a href="https://docs.python.org/2/library/xml.etree.elementtree.html" rel="nofollow" title="ElementTree">ElementTree</a>:</p>
<pre><code>import xml.etree.ElementTree as ET
tree = ET.parse('myfile.xml')
root = tree.getroot()
</code></pre>
<p>然后迭代<code>root</code>及其子级,具体取决于XML数据的外观。你知道吗</p>