Module: MultiXml::Parsers::LibxmlSax Private

Defined in:
lib/multi_xml/parsers/libxml_sax.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

SAX-based parser using LibXML (faster for large documents)

Defined Under Namespace

Classes: Handler

Class Method Summary collapse

Class Method Details

.parse(xml) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parse XML from a string or IO object

Parameters:

  • xml (String, IO)

    XML content

Returns:

  • (Hash)

    Parsed XML as a hash

Raises:

  • (LibXML::XML::Error)

    if XML is malformed



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/multi_xml/parsers/libxml_sax.rb', line 25

def parse(xml)
  io = xml.respond_to?(:read) ? xml : StringIO.new(xml)
  return {} if io.eof?

  LibXML::XML::Error.set_handler(&LibXML::XML::Error::QUIET_HANDLER)
  handler = Handler.new
  parser = ::LibXML::XML::SaxParser.io(io)
  parser.callbacks = handler
  parser.parse
  handler.result
end

.parse_errorClass

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get the parse error class for this parser

Returns:

  • (Class)

    LibXML::XML::Error



17
# File 'lib/multi_xml/parsers/libxml_sax.rb', line 17

def parse_error = ::LibXML::XML::Error