I wanted programmatically store an XML file into a database, then I'll tranform, analyse and visualize data. Since I'm more proficient with python than any other language, I wanted to put the XML into MongoDB. So I'm trying to first convert XML to JSON using xmltodict. I'm using colabs, but it keeps throwing the following ExpatError.
!pip install -q xlrd
!git clone https://github.com/martinblech/xmltodict.git
!pip install xmltodict
import xmltodict
import json
import pprint
from google.colab import files
files.upload() #here I upload customer.xml
with open('customer.xml') as fd:
doc = xmltodict.parse(fd.read())
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(json.dumps(doc))
ExpatError Traceback (most recent call last)
<ipython-input-14-b14a90e48155> in <module>()
1 with open('customer.xml') as fd:
----> 2 doc = xmltodict.parse(fd.read())
3
4 pp = pprint.PrettyPrinter(indent=4)
5 pp.pprint(json.dumps(doc))
/usr/local/lib/python3.6/dist-packages/xmltodict.py in parse(xml_input, encoding, expat, process_namespaces, namespace_separator, disable_entities, **kwargs)
325 parser.ParseFile(xml_input)
326 else:
--> 327 parser.Parse(xml_input, True)
328 return handler.item
329
ExpatError: no element found: line 1, column 0