Module: MultiXML::Parsers::Oga Private

Extended by:
MultiXML::Parser, Oga
Includes:
DomParser
Included in:
Oga
Defined in:
lib/multi_xml/parsers/oga.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.

XML parser using the Oga library

Constant Summary collapse

ParseError =

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

Exception class raised on Oga parse failure

LL::ParserError

Instance Method Summary collapse

Methods included from MultiXML::Parser

parse_error

Methods included from DomParser

#node_to_hash

Instance Method Details

#collect_children(node, node_hash, mode) ⇒ void

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.

This method returns an undefined value.

Collect child nodes into a hash (Oga-specific implementation)

Oga uses different node types than Nokogiri/LibXML.

Parameters:

  • node (Oga::XML::Element)

    Parent node

  • node_hash (Hash)

    Hash to populate

  • mode (Symbol)

    Namespace handling mode



39
40
41
42
43
44
45
46
# File 'lib/multi_xml/parsers/oga.rb', line 39

def collect_children(node, node_hash, mode)
  each_child(node) do |child|
    case child
    when ::Oga::XML::Element then node_to_hash(child, node_hash, mode: mode)
    when ::Oga::XML::Text, ::Oga::XML::Cdata then node_hash[TEXT_CONTENT_KEY] << child.text
    end
  end
end

#parse(io, namespaces: :strip) ⇒ 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 an IO object

Parameters:

  • io (IO)

    IO-like object containing XML

  • namespaces (Symbol) (defaults to: :strip)

    Namespace handling mode

Returns:

  • (Hash)

    Parsed XML as a hash

Raises:

  • (LL::ParserError)

    if XML is malformed



25
26
27
28
# File 'lib/multi_xml/parsers/oga.rb', line 25

def parse(io, namespaces: :strip)
  doc = ::Oga.parse_xml(io)
  node_to_hash(doc.children.first, mode: namespaces)
end