-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxml2csv_openaire.py
More file actions
70 lines (52 loc) · 1.47 KB
/
xml2csv_openaire.py
File metadata and controls
70 lines (52 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os
from xml.etree import ElementTree as et
#base_path = os.path.dirname(os.path.realpath(__file__))
#
#xml_file = os.path.join(base_path, "testovaci_openaire", "openaire_exmaple.xml")
# xml_file = "/home/dobiasj/Projects/xml2csv/input"
#
#tree = et.parse(xml_file)
#
#root = tree.getroot()
def identifier(root):
for field in root.iter('{http://www.driver-repository.eu/namespace/dri}objIdentifier'):
return field.text
'''
def identifier(root):
fields = root.findall(".//{http://www.driver-repository.eu/namespace/dri}objIdentifier")
for field in fields:
return field.attrib["id"]
# if len(field) > 0:
# return field[0].text
'''
def langs(root):
fields = root.findall(".//language")
for field in fields:
return field.attrib["classid"]
'''
for langs in root.iter('language'):
return langs.attrib['classid']
'''
def year(root):
fields = root.findall(".//dateofacceptance")
if fields is not None:
if fields[0].text:
return fields[0].text[:4]
def doc_type(root):
fields = root.findall(".//instancetype[@classname]")
doc = set()
for field in fields:
doc.add(field.attrib["classname"])
return doc
def projects(root):
fields = root.findall(".//rel/code")
codes = []
for field in fields:
codes.append(field.text)
return codes
# if __name__ == "__main__":
# langs(root)
# year(root)
# doc_type(root)
# identifier(root)
# projects(root)