试图解析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