擅长:python、mysql、java
<p>下面的代码生成3个列表</p>
<pre><code>import xml.etree.ElementTree as ET
XML = '''<?xml version="1.0" encoding="utf-8"?> <goals> <goal id="445" name="xxxy" sex="F" />
<goal id="2468" name="qwerzui" sex="F" /> <goal id="4334" name="foo" sex="M" />
<goal id="15" name="fooh" sex="F" />
</goals>
'''
final = []
attributes = ['id', 'name', 'sex']
root = ET.fromstring(XML)
for attrib in attributes:
final.append([g.attrib[attrib] for g in root.findall('goal')])
print(final)
</code></pre>
<p>输出</p>
<pre><code>[['445', '2468', '4334', '15'], ['xxxy', 'qwerzui', 'foo', 'fooh'], ['F', 'F', 'M', 'F']]
</code></pre>