Class: Nokogiri::XML::SAX::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/nokogiri/xml/sax/parser.rb

Direct Known Subclasses

HTML::SAX::Parser

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc = XML::SAX::Document.new) ⇒ Parser

Returns a new instance of Parser.



6
7
8
# File 'lib/nokogiri/xml/sax/parser.rb', line 6

def initialize(doc = XML::SAX::Document.new)
  @document = doc
end

Instance Attribute Details

#documentObject

Returns the value of attribute document.



5
6
7
# File 'lib/nokogiri/xml/sax/parser.rb', line 5

def document
  @document
end

Instance Method Details

#parse(thing) ⇒ Object

Parse given thing which may be a string containing xml, or an IO object.



13
14
15
# File 'lib/nokogiri/xml/sax/parser.rb', line 13

def parse thing
  parse_memory(thing.is_a?(IO) ? thing.read : thing)
end

#parse_file(filename) ⇒ Object

Parse a file with filename

Raises:

  • (Errno::ENOENT)


25
26
27
28
29
# File 'lib/nokogiri/xml/sax/parser.rb', line 25

def parse_file filename
  raise Errno::ENOENT unless File.exists?(filename)
  raise Errno::EISDIR if File.directory?(filename)
  native_parse_file filename
end

#parse_io(io) ⇒ Object

Parse given io



19
20
21
# File 'lib/nokogiri/xml/sax/parser.rb', line 19

def parse_io io
  parse_memory io.read
end