Ngày tốt lành mọi người.Python ElementTree "không tìm thấy phần tử" ngoại lệ
Tôi đang cố đọc, phân tích cú pháp và sử dụng tệp xml bằng ElementTree. Dữ liệu sau:
<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 />
Đáng buồn thay, tôi ElementTree đưa ra một ngoại lệ! Đọc các tập tin với mã sau:
import xml.etree.ElementTree as ET
***code***
tree = ET.parse("res\\data.xml")
root = tree.getroot()
Ngoại lệ:
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***
tôi không thể tìm ra những gì là sai, tôi đã cố gắng để thay đổi data.xml bằng mọi cách có thể, tôi có thể tưởng tượng, không có Sự khác biệt. Nó luôn luôn là dòng cuối cùng của tập tin! Tôi đang làm gì sai? Cảm ơn!
Có vẻ như tôi thuộc nhóm tiệc chào mừng, hôm nay! Chào mừng bạn đến với Stack Overflow @grvsmth. Chúc mừng Tiến sĩ của bạn và tôi hy vọng rằng bạn sẽ 'while (yourStay) {try {StackOverflow} catch {enjoyment}}'. Vâng, đó là một chút, nhưng, hài hước là một trong những điều cuối cùng mà con người chúng ta vẫn có thể làm tốt hơn máy tính. –
Vâng THANK you. Đó là những gì tôi cần. – Nearoo
Rất vui được giúp đỡ và cảm ơn sự chào đón! – grvsmth