I tried to encode the XML file so that it could read the invalid content without problem, however it did not work.
This is my code:
import xml.etree.ElementTree as ET
import io
file_path = r'c:\data\MSM\Energy\XML-files\my_xml.xml'
with io.open(file_path, 'r', encoding='utf-8-sig') as f:
contents = f.read()
tree = ET.fromstring(contents)
This is what I receive:
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 62, column 48
This is how XML file line 62 looks like:
62 <Organisation>Blue & Logistics B.V.</Organisation>
I'm sure it has to do with the & sign, so how can I encode that?