diff --git a/test_xml2bib.py b/test_xml2bib.py index 6ef9650..e5b0f52 100644 --- a/test_xml2bib.py +++ b/test_xml2bib.py @@ -24,5 +24,21 @@ def test_basic(self): if (self.verbose): print('testBasic:', x) + +class TestXMLReader(unittest.TestCase): + def test_one(self): + f = 'xmlfiles/_10.14470_6t569239.xml' + x = xml2bib.XMLReader(f) + d = xml2bib.xml2dict(x) + + c_names = ('Th, H.', + 'Ba, N.', + 'Ma, V.', + 'Ri, J.', + 'Ti, F.',) + c = ' and '.join(c_names) + self.assertEqual(d['author'], c) + + if __name__ == '__main__': unittest.main() diff --git a/xml2bib.py b/xml2bib.py index 9d0797f..da5d6a4 100644 --- a/xml2bib.py +++ b/xml2bib.py @@ -46,7 +46,7 @@ def xml2dict(x): r = x.root #print('DEBUG', r.attrib) - xmlfields = ('identifier', 'title', 'publisher', + xmlfields = ('creator', 'identifier', 'title', 'publisher', 'publicationYear', 'resourceType') #nsd = {'dc': 'http://datacite.org/schema/kernel-4'} ns = '{http://datacite.org/schema/kernel-4}' @@ -55,32 +55,29 @@ def xml2dict(x): for field in xmlfields: #for n in r.findall('dc:' + field, nsd): for n in r.iter(ns + field): + v = n.text + if field == 'creator': + v = n.find(ns + 'creatorName').text + #print('Found', field, v) if n is not None: - v = n.text - #print('Found', field, v) - dc[field] = v - - #for n in r.findall(field): - # print('found', field) - # dc[field] = n.text + if dc[field] is None: + dc[field] = v + else: + dc[field] = dc[field] + ' and ' + v #print('DEBUG dc=', dc) d = dict() - d['authors'] = 'Abbott, A and Costello, C' - dc_to_bib = {'year': 'publicationYear', + dc_to_bib = {'author': 'creator', + 'year': 'publicationYear', 'DOI': 'identifier', + 'howpublished': 'resourceType', 'publisher': 'publisher', 'title': 'title', - 'howpublished': 'resourceType', } for x in dc_to_bib: d[x] = dc[dc_to_bib[x]] -# d['year'] = dc['publicationYear'] -# d['title'] = dc['title'] -# d['DOI'] = dc['identifier'] -# d['publisher'] = dc['publisher'] return d if __name__ == '__main__': @@ -91,5 +88,3 @@ def xml2dict(x): y = xml2dict(x) print(str(BibTeXWriter('ref%i' % (k,), y))) print() - - diff --git a/xmlfiles/_10.14470_6t569239.xml b/xmlfiles/_10.14470_6t569239.xml new file mode 100644 index 0000000..e77cfea --- /dev/null +++ b/xmlfiles/_10.14470_6t569239.xml @@ -0,0 +1,53 @@ + + + 10.14470/6T569239 + + + Th, H. + Ha + Th + + + Ba, N. + Ni + Ba + + + Ma, V. + Va + Ma + + + Ri, J. + Jo + Ri + + + Ti, F. + Fr + Ti + + + + ScanArray Core (1G 2012-2017) + + The ScanArray consortium + 0 + Seismic Network + + Broadband seismic waveforms + Lithosphere + + + + + 2016-05-23 + ? + + + + The ScanArray experiment is a major collaborative effort of institutions in Scandinavia and Germany to map crustal and mantle structure below Scandinavia using a dense temporary deployment of broadband seismometers. +[..] +Waveform data will be fully opened in early 2020. + +