Python元素树“;“未找到任何元素”;例外

Python元素树“;“未找到任何元素”;例外,python,xml,parsing,xml-parsing,elementtree,Python,Xml,Parsing,Xml Parsing,Elementtree,大家好 我正在尝试使用ElementTree读取、解析和使用xml文件。 以下数据: <level> <leveldata> <level name="hh" difficulty="Easy" lenght="3600"> <meteorite chance="4" speed="3" > <image id="1"> &l

大家好

我正在尝试使用ElementTree读取、解析和使用xml文件。 以下数据:

<level>
    <leveldata>
        <level name="hh" difficulty="Easy" lenght="3600">
            <meteorite chance="4" speed="3" >
                <image id="1">
                <image id="2">
                <image id="3">
            <meteorite />
            <meteorite chance="4" speed="3" >
                <image id="4">
                <image id="5">
                <image id="6">
            <meteorite />
        <level />
    <leveldata />
    <meteorimages>
        <meteor id="5" imagepath="res\meteorit_1.png">
        <meteor id="5" imagepath="res\meteorit_2.png">
        <meteor id="5" imagepath="res\meteorit_3.png">
    <meteorimages />
<datasheet />
<level />
例外情况:

File "E:\blabla\core.py", line 26, in load_levelproperties
    *tree = ET.parse("res\\data.xml")*   File "E:\Programme(x86)\Python2.7x86\lib\xml\etree\ElementTree.py", line
1182, in parse
    *tree.parse(source, parser)*   File "E:\Programme(x86)\Python2.7x86\lib\xml\etree\ElementTree.py", line
657, in parse
    *self._root = parser.close()*   File "E:\Programme(x86)\Python2.7x86\lib\xml\etree\ElementTree.py", line
1654, in close
    *self._raiseerror(v)*   File "E:\Programme(x86)\Python2.7x86\lib\xml\etree\ElementTree.py", line
1506, in _raiseerror
    ***raise err xml.etree.ElementTree.ParseError: no element found: line 16, column 9***
我不知道出了什么问题,我试着用我能想象到的所有可能的方式更改data.xml,没有区别。它总是文件的最后一行! 我做错了什么?
谢谢

您的XML格式不正确,
ElementTree
无法解析它-它看起来确实像是真实文档的一部分

以下是格式化后得到的结果:

<level>
    <leveldata>
        <level name="hh" difficulty="Easy" lenght="3600">
            <meteorite chance="4" speed="3">
                <image id="1">
                    <image id="2">
                        <image id="3">
                            <meteorite/>
                            <meteorite chance="4" speed="3">
                                <image id="4">
                                    <image id="5">
                                        <image id="6">
                                            <meteorite/>
                                            <level/>
                                            <leveldata/>
                                            <meteorimages>
                                                <meteor id="5" imagepath="res\meteorit_1.png">
                                                    <meteor id="5" imagepath="res\meteorit_2.png">
                                                        <meteor id="5" imagepath="res\meteorit_3.png">
                                                            <meteorimages/>
                                                            <datasheet/>
                                                            <level/>


您的标签未正确关闭。例如,要关闭“陨石”标签,请使用
而不是

您所说的“格式”是什么意思?我应该如何做得更好?@user3424423我刚刚缩进了xml,这样更容易看出xml的结构不正确。Elementtree无法处理它。这对我毫无帮助。我必须做得更好的是什么?为了向现在遇到的任何人澄清上述旧答案:“close”标记是错误的,而不是-这将创建一个新标记,嵌套在预期要关闭的标记下,而不是关闭它。将/移到标记名称的前面将纠正部分问题,并为其他条目添加关闭标记。
<level>
    <leveldata>
        <level name="hh" difficulty="Easy" lenght="3600">
            <meteorite chance="4" speed="3">
                <image id="1">
                    <image id="2">
                        <image id="3">
                            <meteorite/>
                            <meteorite chance="4" speed="3">
                                <image id="4">
                                    <image id="5">
                                        <image id="6">
                                            <meteorite/>
                                            <level/>
                                            <leveldata/>
                                            <meteorimages>
                                                <meteor id="5" imagepath="res\meteorit_1.png">
                                                    <meteor id="5" imagepath="res\meteorit_2.png">
                                                        <meteor id="5" imagepath="res\meteorit_3.png">
                                                            <meteorimages/>
                                                            <datasheet/>
                                                            <level/>