Python cElementTree.ParseError:格式不正确(无效令牌)

Python cElementTree.ParseError:格式不正确(无效令牌),python,python-2.7,xml-parsing,Python,Python 2.7,Xml Parsing,我有一个大型XML文件(200万对象的详细信息),其内容类似于如下所示。文件大小为657MB <?xml version="1.0" encoding="UTF-8?> <root> <item> <rank>1</rank> <landinglink>www.google.com</landinglink> <descrip>some text

我有一个大型XML文件(200万对象的详细信息),其内容类似于如下所示。文件大小为657MB

<?xml version="1.0" encoding="UTF-8?>
<root>
    <item>
        <rank>1</rank>
        <landinglink>www.google.com</landinglink>
        <descrip>some text</descrip>
    </item>
    <item>
        <rank>1</rank>
        <landinglink>www.facebook.com</landinglink>
        <descrip>some text</descrip>
    </item>
    <item>
        <rank>1</rank>
        <landinglink>www.xyz.com</landinglink>
        <descrip>some text</descrip>
    </item>
    .
    .
    .
    .
    .
    .
    .
</root>
但是在执行代码时,它给了我以下错误

    Traceback (most recent call last):
  File "D:/test.py", line 2, in <module>
    for event, elem in ET.iterparse("filename.xml"):
  File "<string>", line 91, in next
cElementTree.ParseError: not well-formed (invalid token): line 1338, column 298
回溯(最近一次呼叫最后一次):
文件“D:/test.py”,第2行,在
对于事件,ET.iterparse(“filename.xml”)中的元素:
文件“”,第91行,下一页
cElementTree.ParseError:格式不正确(无效令牌):第1338行第298列
此错误在不同的位置不断重复。如何避免此类错误。任何帮助都将不胜感激。

(作为后续读者的答案发布)

如果错误标记值为
\xA0
,则文件未正确编码为utf-8。

如果文件只有8位字符,则需要将XML声明更改为其他内容,可能是

该行上的该位置是什么?一些文本描述,但它包含xA0类错误如果值为
\xA0
,那么您的文件没有正确编码为utf-8。如何解决此问题我要尝试的第一件事是将XML声明更改为
,然后看看会发生什么。
    Traceback (most recent call last):
  File "D:/test.py", line 2, in <module>
    for event, elem in ET.iterparse("filename.xml"):
  File "<string>", line 91, in next
cElementTree.ParseError: not well-formed (invalid token): line 1338, column 298