試圖解析XML文件轉換成ElementTree的:Python的XML:ParseError:文檔元素後的垃圾
>>> import xml.etree.cElementTree as ET
>>> tree = ET.ElementTree(file='D:\Temp\Slikvideo\JPEG\SV_4_1_mask\index.xml')
我獲得以下錯誤:
Traceback (most recent call last): File "", line 1, in File "C:\Program Files\Anaconda2\lib\xml\etree\ElementTree.py", line 611, in init self.parse(file) File "", line 38, in parse ParseError: junk after document element: line 3, column 0
XML文件開始是這樣的:
<?xml version="1.0" encoding="UTF-8" ?>
<Version Writer="E:\d\src\Modules\SceneSerialization\src\mitkSceneIO.cpp" Revision="$Revision: 17055 $" FileVersion="1" />
<node UID="OBJECT_2016080819041580480127">
<source UID="OBJECT_2016080819041550469454" />
<data type="LabelSetImage" file="hfbaaa_Bolus.nrrd" />
<properties file="sicaaa" />
</node>
<node UID="OBJECT_2016080819041512769572">
<source UID="OBJECT_2016080819041598947781" />
<data type="LabelSetImage" file="ifbaaa_Bolus.nrrd" />
<properties file="ticaaa" />
</node>
其次是更多的節點。
我沒有看到第3行第0列有任何垃圾?我認爲這個錯誤肯定還有其他原因。
.xml文件由外部軟件MITK生成,所以我認爲應該沒問題。
在Win 7中,64位,VS2015,阿納康達
XML格式不正確。沒有包含所有其他元素的根元素。 –
與這個問題無關,您應該考慮轉義Windows路徑字符串文本(「... \\ ...」)或使用原始字符串(r「... \ ...」)。 –
@Martin:謝謝,同意。在代碼的其他部分完成。 – jdelange