lib/bolognese/datacite_utils.rb in bolognese-0.9.5 vs lib/bolognese/datacite_utils.rb in bolognese-0.9.6
- old
+ new
@@ -1,11 +1,11 @@
module Bolognese
module DataciteUtils
- SCHEMA = File.expand_path("../../../resources/kernel-4.0/metadata.xsd", __FILE__)
-
def schema
- Nokogiri::XML::Schema(open(SCHEMA))
+ kernel = schema_version.split("/").last || "kernel-4.0"
+ filepath = File.expand_path("../../../resources/#{kernel}/metadata.xsd", __FILE__)
+ Nokogiri::XML::Schema(open(filepath))
end
def datacite_xml
@datacite_xml ||= Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
xml.resource(root_attributes) do
@@ -17,10 +17,12 @@
def datacite
datacite_xml
end
def datacite_errors
- @datacite_errors ||= schema.validate(Nokogiri::XML(datacite, nil, 'UTF-8')).map { |error| error.to_s }
+ schema.validate(Nokogiri::XML(datacite, nil, 'UTF-8')).map { |error| error.to_s }.unwrap
+ rescue Nokogiri::XML::SyntaxError => e
+ e.message
end
def insert_work(xml)
insert_identifier(xml)
insert_creators(xml)