Topic: Ruby on Rails test for valid XML via XSD file
Hi all together
I try to evaluate an XML file (EML) in a Ruby on Rails test against a XSD file. The XML gets generated by a view and my test looks like this at the moment.
test "eml is valid" do
# require the xml library
require 'libxml'
# call eml view of a dataset
get :show, {:id => Dataset.find_by_id(5), :format => :eml}
# get eml file from call
@xml_file = @response.body
# define standard
@xsd_file = "test/fixtures/test_files_for_eml/eml-2.1.0/eml.xsd"
# prepare files for validation
document = LibXML::XML::Document.file(@xml_file)
schema = LibXML::XML::Schema.new(@xsd_file)
# valiadte files
result = document.validate_schema(schema) do |message,flag|
log.debug(message)
puts message
end
endThis test does not work and I get error messages that say:
Warning: failed to load external entity "<?xml version="1.0"
encoding="utf-8"?>
LibXML::XML::Error: Warning: failed to load external entity "<?xml
version="1.0" encoding="utf-8"?>In a next step I replaced the "@response.body" by a manually generated XML file on the file system.
test "eml is valid" do
# require the xml library
require 'libxml'
# call eml view of a dataset
get :show, {:id => Dataset.find_by_id(5), :format => :eml}
# get eml file from call
@xml_file = "/home/example/Downloads/9.eml"
# define standard
@xsd_file = "test/fixtures/test_files_for_eml/eml-2.1.0/eml.xsd"
# prepare files for validation
document = LibXML::XML::Document.file(@xml_file)
schema = LibXML::XML::Schema.new(@xsd_file)
# valiadte files
result = document.validate_schema(schema) do |message,flag|
log.debug(message)
puts message
end
endThis evaluation test works fine. So now my question is how I can get this to work right
with a created response and not with a file, or with an automated download of the file
generated from the view to a temporary directory for evaluation. Any help would be appreciated.
Best regards Claas
Last edited by cpfaff (2012-09-20 06:01:48)