Class: RNV::Validator
- Inherits:
-
Object
- Object
- RNV::Validator
- Defined in:
- lib/rnv/validator.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#errors ⇒ Array<RNV::Error>
errors from document.
-
#initialize ⇒ Validator
constructor
A new instance of Validator.
-
#load_schema_from_file(file) ⇒ Boolean
True if schema loaded successfuly.
-
#load_schema_from_string(str) ⇒ Boolean
True if schema loaded successfuly.
-
#parse_file(xml, pre_processor = PreProcessor.new) ⇒ Boolean
parse and validate file.
-
#parse_string(str, pre_processor = PreProcessor.new) ⇒ Boolean
parse and validate buffer.
Constructor Details
#initialize ⇒ Validator
Returns a new instance of Validator.
52 53 54 |
# File 'lib/rnv/validator.rb', line 52 def initialize @document = RNV::Document.new end |
Instance Attribute Details
#document ⇒ RNV::Document
50 51 52 |
# File 'lib/rnv/validator.rb', line 50 def document @document end |
Instance Method Details
#errors ⇒ Array<RNV::Error>
errors from document
58 59 60 |
# File 'lib/rnv/validator.rb', line 58 def errors @document.errors end |
#load_schema_from_file(file) ⇒ Boolean
Returns true if schema loaded successfuly.
70 71 72 |
# File 'lib/rnv/validator.rb', line 70 def load_schema_from_file(file) @document.load_file(file) end |
#load_schema_from_string(str) ⇒ Boolean
Returns true if schema loaded successfuly.
64 65 66 |
# File 'lib/rnv/validator.rb', line 64 def load_schema_from_string(str) @document.load_string(str) end |
#parse_file(xml, pre_processor = PreProcessor.new) ⇒ Boolean
parse and validate file
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/rnv/validator.rb', line 98 def parse_file(xml, pre_processor = PreProcessor.new) @document.start_document rnv_doc = NokogiriSaxDocument.new(@document) rnv_doc.pre_processor = pre_processor file = xml.is_a?(File) ? xml : File.open(xml) raise RNV::DocumentEmpty if file.size == 0 parser = Nokogiri::XML::SAX::Parser.new(rnv_doc) parser.parse(file) do |ctx| ctx.replace_entities = true rnv_doc.ctx = ctx end @document.valid? end |
#parse_string(str, pre_processor = PreProcessor.new) ⇒ Boolean
parse and validate buffer
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/rnv/validator.rb', line 78 def parse_string(str, pre_processor = PreProcessor.new) @document.start_document rnv_doc = NokogiriSaxDocument.new(@document) rnv_doc.pre_processor = pre_processor raise RNV::DocumentEmpty if str.nil? or str.empty? parser = Nokogiri::XML::SAX::Parser.new(rnv_doc) parser.parse_memory(str) do |ctx| ctx.replace_entities = true rnv_doc.ctx = ctx end @document.valid? end |