We can use python xml.dom.minidom package to parse a xml file.
Here is an example:
However, you may get this error: xml.parsers.expat.ExpatError: XML or text declaration not at start of entity. In this tutorial, we will introduce you how to fix this error.
As to our code, the full error is:
xml.parsers.expat.ExpatError: XML or text declaration not at start of entity: line 2, column 0
We can find the error occur in line 2 and column 0.
How to fix this error?
Open xml file and look at the line 2.
We can find there is an empty line in this file.
Remove this empty line.
Run code again, we will find this error is fixed.