简体   繁体   中英

XSD Schema Validation in Ruby

I have found several sources regarding how to validate an xml document against a schema, but I have an application in ruby in which I need to validate that a user supplied schema is a valid schema itself. Is there a way to that I can check this? Is there an XSD schema to validate an XSD schema? Or are there libraries or gems that do this for me?

You can use Nokogiri for this:

begin
  schema = Nokogiri::XML::Schema(File.read('invalid_schema.xsd'))
rescue Nokogiri::XML::SyntaxError => e
  puts "Invalid XML Schema!"
end

As schemas are XML documents themselves you can validate them like any other document. Both an XSD and a DTD for XML Schema can be found on this site http://www.w3.org/2001/XMLSchema .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM