When using Nokogiri to validate an XML document against multiple XML Schema files using import declarations, ensure that you use File.open rather than File.read as shown in the Nokogiri::XML::Schema documentation. This will allow Nokogiri to navigate to and read these imported schemas.
Thanks to this StackOverflow post.
a.xsd
[pyg l=xml]
[/pyg]
b.xsd
[pyg l=xml]
[/pyg]
example.xml
[pyg l=xml]
[/pyg]
validate.rb
[pyg l=ruby]
xsd = Nokogiri::XML::Schema(File.open(‘a.xsd’))
doc = Nokogiri::XML(File.read(‘example.xml’))
xsd.validate(doc).each do |error|
puts error.message
end
[/pyg]