Good day everybody.

大家好日子。

I'm trying to read, parse and use an xml-file using ElementTree. Following data:

我正在尝试使用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 />

Sadly, I ElementTree gives an exception!!! Reading the file with following code:

可悲的是,我的ElementTree给了一个例外!!!使用以下代码读取文件:

import xml.etree.ElementTree as ET
***code***
tree = ET.parse("res\\data.xml")
root = tree.getroot()

Exception:

例外:

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***

I can't figure out what's wrong, I've tried to change data.xml in every possible way I can imagine, no difference. It's always the last line of the file! What am I doing wrong? Thanks!

我无法弄清楚出了什么问题,我试图以我能想象的每一种可能的方式改变data.xml,没有区别。它始终是文件的最后一行!我究竟做错了什么?谢谢!

2 个解决方案

#1


4

Your tags are not closed properly. For example, to close a "meteorite" tag, use </meteorite> not <meteorite />.

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

更多相关文章

  1. python 处理csv文件的过程对换行符的处理
  2. linux修改文件所属用户和组
  3. 八大经典排序算法基本思想及代码实现(插入排序,希尔排序,选择排序,
  4. 贝叶斯学习 -- matlab、python代码分析(3)
  5. Linux的文件权限
  6. linux系统更改目录和文件的权限总结
  7. UNIX-LINUX编程实践教程->第八章->实例代码注解->写一个简单的sh
  8. Linux下objdump查看C程序编译后的汇编代码
  9. CentOS7.2 通过nfs设置共享文件夹

随机推荐

  1. Android(安卓)APN的设置问题:默认“已起用
  2. android cmd adb命令安装和删除apk应用
  3. 区分android:gravity与android:layout_gr
  4. Android 应用程序之道
  5. Android OS历史版本
  6. Android系统介绍及平台特性
  7. Android加密之文件级加密
  8. Android系统构架分析和应用程序目录结构
  9. 各种类型Android Market了解
  10. android遮罩层