我有xml:
<?xml version="1.0" encoding="UTF-8"?>
<rows>
<row>
<ro new="TEMP_1">TEMP_11</ro>
<ro new="TEMP_2">TEMP_12</ro>
<ro new="TEMP_3">TEMP_13</ro>
</row>
<row>
<ro new="TEMP_1">TEMP_14</ro>
<ro new="TEMP_2">TEMP_15</ro>
<ro new="TEMP_3">TEMP_16</ro>
</row>
</rows>
和解析器:
import xml.etree.cElementTree as ET
context = ET.iterparse('temp.xml', events=("start", "end"))
context = iter(context)
outList = []
for event,elem in context:
tag = elem.tag
value = elem.text
outList.append(value)
print outList
当 print outList 我收到:
['\n', '\n', 'TEMP_11', 'TEMP_11', 'TEMP_12', 'TEMP_12', 'TEMP_13', 'TEMP_13', '\n', '\n', 'TEMP_14', 'TEMP_14', 'TEMP_15', 'TEMP_15', 'TEMP_16', 'TEMP_16', '\n', '\n']
为什么我在列表中收到重复值?如何解决?