我需要迭代 100 多个 xml 文件,而不会出现此错误:“ParseError:XML 或文本声明不在实体开头:第 2 行,第 0 列”。我该怎么做?现在,我已经完成了:
import xml.etree.ElementTree as ET
import os
file_1 = ' '.join([x for x in os.listdir() if x.endswith('xml')])
utterances = []
for filename in file_1.split():
with open(filename, 'r', encoding="utf-8") as content:
tree = ET.parse(content)
root = tree.getroot()
for y in root.iter('UNIT'):
utterances.append(y.text)