I want to convert multiple XML files to JSON files. Thing is, the XML files are always different, so they have different childs. My current code only gets the childs, not the values.
What I need:
What I need:
- Get childs and values from multiple xml files which can be different
- Put that in a JSON file.
import xml.etree.ElementTree as ET
from os import listdir, chdir
path = (r'C:\Users\path..')
chdir(path)
files = [f for f in listdir(path)]
elemlist = {}
for bestand in files:
xmltree = ET.parse(bestand)
for elem in xmltree.iter():
elemlist[elem.tag] = elem.attrib
#elemlist.append(elem.tag)
#elemlist = list(set(elemlist))
print(elemlist)
Comments
Post a Comment