I have xml file like this :
<?xml version="1.0" encoding="UTF-8"?>
<Main xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns="http://cnig.gouv.fr/pcrs" gml:id="PlanCorpsRueSimplifie.1" version="2.0">
<gml:boundedBy>
</gml:boundedBy>
<featureMember>
<EmpriseEchangePCRS gml:id="EmpriseEchangePCRS.12189894">
<datePublication>2020-05-13</datePublication>
<type>Cellules</type>
<geometrie>
<gml:MultiSurface gml:id="EmpriseEchangePCRS.12189894-0" srsName="EPSG:3944" srsDimension="3">
<gml:surfaceMember>
<gml:Surface gml:id="EmpriseEchangePCRS.12189894-1">
<gml:patches>
</gml:patches>
</gml:Surface>
I wouldike to transform this file into json file. I tried this but I have always the same error :
import xmltodict
import xml.etree.ElementTree as ET
root = ET.fromstring(open('JeuxTestv2.gml').read())
print(xmltodict.parse(root)['Main'])
ERROR :
Traceback (most recent call last):
File "C:\Users\xmltodict.py", line 6, in <module>
print(xmltodict.parse(root)['Main'])
File "C:\Users\xmltodict.py", line 327, in parse
parser.Parse(xml_input, True)
TypeError: a bytes-like object is required, not 'xml.etree.ElementTree.Element'
xmltodict.parsedirectly, without the need to useElementTree. E.g.print(xmltodict.parse(open('JeuxTestv2.gml'))).