1

I am trying to read an xml file with different encoding. In case of UTF-8 it is working fine but in case of other formats like GB18030 or BIG5, it is throwing error like multi-byte encoding are not supported.

Please suggest a solution for this. Thanks in advance.

Rahul K P
  • 15,740
  • 4
  • 35
  • 52
  • 3
    Welcome to StackOverflow! Please read the info about [how to ask a good question](https://stackoverflow.com/help/how-to-ask) and [how to give a reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). This will make it much easier for others to help you. – Aditi Feb 20 '18 at 09:59

1 Answers1

0

Here a try is open as file object and with ElementTree.fromstring() :

import xml.etree.ElementTree as ET

with open('file_name.xml','r') as f:
   ef = ET.fromstring(f.read())

It was worked for me.

Or you can do is with XMLParser :

xmlp = ET.XMLParser(encoding="utf-8")
f = ET.parse('file_name.xml',parser=xmlp)
Vikas Periyadath
  • 3,088
  • 1
  • 21
  • 33