class Riddl::Handlers::RelaxNG

Public Class Methods

handle(what,hinfo) click to toggle source
# File lib/ruby/riddl/handlers/relaxng.rb, line 4
def self::handle(what,hinfo)
  begin
    w = if what.class == Riddl::Parameter::Tempfile || what.class == File
      XML::Smart.open_unprotected(what)
    else
      XML::Smart.string(what)
    end
    rng = XML::Smart.string("<payload>" + hinfo + "</payload>")
    rng.register_namespace 'r', 'http://relaxng.org/ns/structure/1.0'
    w.validate_against(rng.find("//r:grammar|//r:element").first.to_doc) rescue false
  rescue
    puts 'The XML sent to the server is b0rked/>'
    false
  end
end