Module: AXML

Extended by:
AXML
Included in:
AXML, LibXML, XMLParser
Defined in:
lib/axml.rb,
lib/axml/el.rb,
lib/axml/libxml.rb,
lib/axml/autoload.rb

Defined Under Namespace

Modules: Autoload Classes: El, LibXML, XMLParser

Constant Summary collapse

DEFAULTS =

note that if Autoload must find a suitable parser, it will be set as the :parser default to be used for future reference.

{:keep_blanks => false, :parser => nil}
PREFERRED =
[:xmlparser, :libxml, :libxml_sax, :rexml]
CLASS_MAPPINGS =
{:xmlparser => 'XMLParser', :libxml => 'LibXML', :libxml_sax => 'libXMLSax', :rexml => 'REXML' }
WARN =
{:rexml => "Using REXML as parser!  This is very slow on large docs!\nCall the method AXML::Autoload.install_instructions for help installing\nsomething FASTER!",
}

Instance Method Summary collapse

Instance Method Details

#parse(arg, opts = {}) ⇒ Object

opts:

:parser =


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/axml.rb', line 15

def parse(arg, opts={})
  opts = DEFAULTS.merge opts
  parser = AXML::Autoload.parser!(opts[:parser])
  method = 
    if arg.is_a?(String) && File.exist?(arg)
      :parse_file
    elsif arg.is_a?(IO)
      :parse_io
    elsif arg.is_a?(String)
      :parse_string
    else
      raise ArgumentError, "can deal with filenames, Strings, and IO objects.\nDon't know how to work with object of class: #{arg.class}"
    end
  parser.send(method, arg, opts)
end

#parse_file(file, opts = {}) ⇒ Object

:nodoc:



31
32
33
34
35
# File 'lib/axml.rb', line 31

def parse_file(file, opts={}) # :nodoc:
  opts = DEFAULTS.merge opts
  parser = AXML::Autoload.parser!(opts[:parser])
  File.open(file) {|fh| parser.parse_io(fh, opts) }
end