Class: Riddl::Handlers::RelaxNG

Inherits:
Implementation show all
Defined in:
lib/ruby/riddl/handlers/relaxng.rb

Class Method Summary collapse

Class Method Details

.handle(what, hinfo) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 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