Class: SvgConform::SaxDocument
- Inherits:
-
Object
- Object
- SvgConform::SaxDocument
- Defined in:
- lib/svg_conform/sax_document.rb
Overview
SAX-based document for streaming validation Provides high-performance validation for large SVG files without loading entire DOM tree into memory
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(content, file_path = nil) ⇒ SaxDocument
constructor
A new instance of SaxDocument.
-
#to_dom ⇒ Object
For compatibility - convert to DOM when needed.
-
#validate_with_profile(profile) ⇒ Object
Validate using SAX streaming parser.
Constructor Details
#initialize(content, file_path = nil) ⇒ SaxDocument
Returns a new instance of SaxDocument.
21 22 23 24 |
# File 'lib/svg_conform/sax_document.rb', line 21 def initialize(content, file_path = nil) @content = content @file_path = file_path end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
11 12 13 |
# File 'lib/svg_conform/sax_document.rb', line 11 def content @content end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
11 12 13 |
# File 'lib/svg_conform/sax_document.rb', line 11 def file_path @file_path end |
Class Method Details
.from_content(content) ⇒ Object
17 18 19 |
# File 'lib/svg_conform/sax_document.rb', line 17 def self.from_content(content) new(content, nil) end |
.from_file(file_path) ⇒ Object
13 14 15 |
# File 'lib/svg_conform/sax_document.rb', line 13 def self.from_file(file_path) new(File.read(file_path), file_path) end |
Instance Method Details
#to_dom ⇒ Object
For compatibility - convert to DOM when needed
42 43 44 |
# File 'lib/svg_conform/sax_document.rb', line 42 def to_dom Document.from_content(@content) end |
#validate_with_profile(profile) ⇒ Object
Validate using SAX streaming parser
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/svg_conform/sax_document.rb', line 27 def validate_with_profile(profile) handler = SaxValidationHandler.new(profile) parser = Nokogiri::XML::SAX::Parser.new(handler) begin parser.parse(@content) rescue StandardError => e # Handle parse errors handler.add_parse_error(e) end handler.result end |