已解决xmL.parsers.expat.ExpatError: no eLement found: Line 1, column 0

已解决(Python读取xml文件报错)xmL.parsers.expat.ExpatError: no eLement found: Line 1, column 0







报错代码


粉丝群里的一个小伙伴想用Python读取xml文件报错:

在这里插入图片描述

报错信息

xmL.parsers.expat.ExpatError: no eLement found: Line 1, column 0


报错翻译


报错信息翻译

xml.解析器.报错:未找到元素:第1行第0列



报错原因


报错原因:如果xml文件不以<?xml...?> 开头,会报这个错误。



解决方法


修改改为正确xml文件格式,如:

<?xml version="1.0” encoding=' "UTF-8" standalone=" no”?>
<collection shelf="New Arrivals">
	<class className="1班">
	   <code>2022001</code>
	   <number>10</number>
	   <teacher>小白</teacher>
	</class>
	<class className="2班">
	   <code>2022002</code>
	   <number>20</number>
	   <teacher>小红</teacher>
	</class>
	<class className="3班">
	   <code>2022003</code>
	   <number>30</number>
	   <teacher>小黑</teacher>
	</class>
</collection>

猜你喜欢

转载自blog.csdn.net/yuan2019035055/article/details/126197239