Class: Saxxy::Parsers::Libxml

Inherits:
Base
  • Object
show all
Defined in:
lib/saxxy/parsers/libxml.rb

Instance Attribute Summary

Attributes inherited from Base

#context_tree, #options

Instance Method Summary collapse

Constructor Details

#initialize(context_tree, options = {}) ⇒ Libxml


9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/saxxy/parsers/libxml.rb', line 9

def initialize(context_tree, options = {})
  super
  @__internal_context_options =
    case options[:mode]
    when :html, nil
      LibXML::XML::Parser::Options::RECOVER |
      LibXML::XML::Parser::Options::NOERROR |
      LibXML::XML::Parser::Options::NOWARNING |
      LibXML::XML::Parser::Options::NONET
    when :xml
      LibXML::XML::Parser::Options::RECOVER |
      LibXML::XML::Parser::Options::NONET
    end
end

Instance Method Details

#parse_file(path_to_file, encoding = LibXML::XML::Encoding::UTF_8) ⇒ Object


28
29
30
# File 'lib/saxxy/parsers/libxml.rb', line 28

def parse_file(path_to_file, encoding = LibXML::XML::Encoding::UTF_8)
  parse_with LibXML::XML::SaxParser.new(build_context(:file, path_to_file, encoding))
end

#parse_io(io, encoding = LibXML::XML::Encoding::UTF_8) ⇒ Object


32
33
34
# File 'lib/saxxy/parsers/libxml.rb', line 32

def parse_io(io, encoding = LibXML::XML::Encoding::UTF_8)
  parse_with LibXML::XML::SaxParser.new(build_context(:io, io, encoding))
end

#parse_string(string, encoding = LibXML::XML::Encoding::UTF_8) ⇒ Object


24
25
26
# File 'lib/saxxy/parsers/libxml.rb', line 24

def parse_string(string, encoding = LibXML::XML::Encoding::UTF_8)
  parse_with LibXML::XML::SaxParser.new(build_context(:string, string, encoding))
end