import sys
from xmlutils.xml2csv import xml2csv
import os
import 	xml.etree.ElementTree as et

if not os.path.exists('converted_versions'):
	os.makedirs('converted_versions')
if not os.path.exists('converted_versions/dataset'):
	os.makedirs('converted_versions/dataset')
if not os.path.exists('converted_versions/grant'):
	os.makedirs('converted_versions/grant')
if not os.path.exists('converted_versions/publication'):
	os.makedirs('converted_versions/publication')
if not os.path.exists('converted_versions/researcher'):
	os.makedirs('converted_versions/researcher')
if not os.path.exists('converted_versions/relation'):
	os.makedirs('converted_versions/relation')
	
numberOfFiles = 0
numberOfFilesProcessed = 0
for xmlfile in os.listdir('.'):
	if xmlfile.endswith(".xml"):
		numberOfFiles += 1
	
for input_file in os.listdir('.'):
	if input_file.endswith(".xml"):
		numberOfFilesProcessed += 1
		NoHeader = False
		
		if numberOfFilesProcessed == 0:
			NoHeader = True
		else:
			NoHeader = False
		
		print("Converting " + input_file + " " + str(numberOfFilesProcessed) + " files out of " + str(numberOfFiles) + " completed")
		tree = et.parse(input_file)
		root = tree.getroot()
		if root.findall('{http://researchgraph.org/schema/v2.0/xml/nodes}datasets'): 
			converter = xml2csv(input_file,"./converted_versions/dataset/" + input_file.split('.xml')[0] + ".csv",noheader=NoHeader)
			converter.convert(tag="{http://researchgraph.org/schema/v2.0/xml/nodes}dataset")

		if root.findall('{http://researchgraph.org/schema/v2.0/xml/nodes}grants'): 
			converter = xml2csv(input_file,"./converted_versions/grant/" + input_file.split('.xml')[0] + ".csv",noheader=NoHeader)
			converter.convert(tag="{http://researchgraph.org/schema/v2.0/xml/nodes}grant")

		if root.findall('{http://researchgraph.org/schema/v2.0/xml/nodes}publications'): 
			converter = xml2csv(input_file,"./converted_versions/publication/" + input_file.split('.xml')[0] + ".csv",noheader=NoHeader)
			converter.convert(tag="{http://researchgraph.org/schema/v2.0/xml/nodes}publication")

		if root.findall('{http://researchgraph.org/schema/v2.0/xml/nodes}researchers'): 	
			converter = xml2csv(input_file,"./converted_versions/researcher/" + input_file.split('.xml')[0] + ".csv",noheader=NoHeader)
			converter.convert(tag="{http://researchgraph.org/schema/v2.0/xml/nodes}researcher")

		if root.findall('{http://researchgraph.org/schema/v2.0/xml/nodes}relations'): 
			converter = xml2csv(input_file,"./converted_versions/relation/" + input_file.split('.xml')[0] + ".csv",noheader=NoHeader)
			converter.convert(tag="{http://researchgraph.org/schema/v2.0/xml/nodes}relation")

@@ -1361,34 +1361,16 @@
 + %22.csv%22
-,noheader=NoHeader
 )%0A%09%09%09con
@@ -1445,16 +1445,34 @@
 dataset%22
+,noheader=NoHeader
 )%0A%0A%09%09if 
@@ -1646,34 +1646,16 @@
 + %22.csv%22
-,noheader=NoHeader
 )%0A%09%09%09con
@@ -1728,16 +1728,34 @@
 s%7Dgrant%22
+,noheader=NoHeader
 )%0A%0A%09%09if 
@@ -1941,34 +1941,16 @@
 + %22.csv%22
-,noheader=NoHeader
 )%0A%09%09%09con
@@ -2029,16 +2029,34 @@
 ication%22
+,noheader=NoHeader
 )%0A%0A%09%09if 
@@ -2241,34 +2241,16 @@
 + %22.csv%22
-,noheader=NoHeader
 )%0A%09%09%09con
@@ -2328,16 +2328,34 @@
 earcher%22
+,noheader=NoHeader
 )%0A%0A%09%09if 
@@ -2535,34 +2535,16 @@
 + %22.csv%22
-,noheader=NoHeader
 )%0A%09%09%09con
@@ -2620,10 +2620,28 @@
 elation%22
+,noheader=NoHeader
 )%0A

Update xml2csv.py