0
다음과 같은 내용을 가진 대형 XML 파일 (200 만 개 세부 객체)이 있습니다. 파일 크기는 657MB입니다.cElementTree.ParseError : 형식이 올바르지 않습니다 (토큰이 유효하지 않습니다)
<?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>
모든 '방문 링크'를 인쇄하려고합니다. 내가 사용하고있는 코드는 다음과 같습니다.
import xml.etree.cElementTree as ET
for event, elem in ET.iterparse("filename.xml"):
if event == 'end' and elem.tag == 'item':
print elem.find('landinglink').text
그러나 코드를 실행하는 동안 다음과 같은 오류가 발생합니다.
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
이 오류는 다른 위치에서 계속 반복됩니다. 이 오류 유형을 피하는 방법. 어떤 도움을 주시면 감사하겠습니다.
해당 위치에있는 행은 무엇입니까? – cco
일부 텍스트 설명이지만 xA0 종류의 오류가 있습니다 –
값이'\ xA0'이면 파일이 utf-8로 올바르게 인코딩되지 않습니다. – cco