diff --git a/lib/bolognese/datacite_utils.rb b/lib/bolognese/datacite_utils.rb index 0cdd0ab9..a5ae5f5e 100644 --- a/lib/bolognese/datacite_utils.rb +++ b/lib/bolognese/datacite_utils.rb @@ -11,7 +11,13 @@ def datacite_xml end def datacite_errors(xml: nil, schema_version: nil) - schema_version = schema_version.to_s.start_with?("http://datacite.org/schema/kernel") ? schema_version : "http://datacite.org/schema/kernel-4" + if xml.present? + namespaces = Nokogiri::XML(xml, nil, 'UTF-8').root.namespaces + schema_version = namespaces.fetch('xmlns',nil).presence || namespaces.fetch('xmlns:ns0',nil).presence + else + schema_version = schema_version.to_s.start_with?("http://datacite.org/schema/kernel") ? schema_version : "http://datacite.org/schema/kernel-4" + end + kernel = schema_version.to_s.split("/").last filepath = File.expand_path("../../../resources/#{kernel}/metadata.xsd", __FILE__) schema = Nokogiri::XML::Schema(open(filepath)) diff --git a/spec/writers/bibtex_writer_spec.rb b/spec/writers/bibtex_writer_spec.rb index d282f744..d35dbbe8 100644 --- a/spec/writers/bibtex_writer_spec.rb +++ b/spec/writers/bibtex_writer_spec.rb @@ -19,6 +19,18 @@ expect(bibtex[:copyright]).to eq("Creative Commons Attribution 3.0 Unported") end + it "with schema_3" do + # input = fixture_path + "datacite_kernel_3.json" + input = fixture_path + "datacite_schema_3.xml" + json = Bolognese::Metadata.new(input: input, from: "datacite") + subject = Bolognese::Metadata.new(input: json.meta.to_json, from: "datacite_json") + bibtex = BibTeX.parse(subject.bibtex).to_a(quotes: '').first + expect(bibtex[:bibtex_type].to_s).to eq("misc") + expect(bibtex[:bibtex_key]).to eq("https://doi.org/10.5061/dryad.8515") + expect(bibtex[:doi]).to eq("10.5061/dryad.8515") + expect(bibtex[:year]).to eq("2011") + end + it "with pages" do input = "https://doi.org/10.1155/2012/291294" subject = Bolognese::Metadata.new(input: input, from: "crossref")