Class: TemplateValidator
- Inherits:
-
ActiveModel::Validator
- Object
- ActiveModel::Validator
- TemplateValidator
- Defined in:
- app/validators/template_validator.rb
Constant Summary collapse
Instance Method Summary collapse
Instance Method Details
#validate(record) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/validators/template_validator.rb', line 6 def validate(record) begin rng = Nokogiri::XML::RelaxNG(File.read(@@template_rng)) xml = Nokogiri::XML(record.xml) { |config| config.strict } rng.validate(xml).each do |error| record.errors.add :xml, error. end rescue Nokogiri::XML::SyntaxError => e record.errors.add :xml, "Syntax error on line #{e.line} at column #{e.column}: #{e.}" end end |