Module: MultiXml::Parsers::DomParser Private

Included in:
Libxml, Nokogiri, Oga
Defined in:
lib/multi_xml/parsers/dom_parser.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.

Shared DOM traversal logic for converting XML nodes to hashes

Used by Nokogiri, LibXML, and Oga parsers. Including modules must implement:

  • each_child(node) { |child| ... }
  • each_attr(node) { |attr| ... }
  • node_name(node) -> String

Instance Method Summary collapse

Instance Method Details

#node_to_hash(node, hash = {}) ⇒ 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.

Convert an XML node to a hash representation

Parameters:

  • node (Object)

    XML node to convert

  • hash (Hash) (defaults to: {})

    Accumulator hash for results

Returns:

  • (Hash)

    Hash representation of the node



19
20
21
22
23
24
25
26
# File 'lib/multi_xml/parsers/dom_parser.rb', line 19

def node_to_hash(node, hash = {})
  node_hash = {TEXT_CONTENT_KEY => +""}
  add_value(hash, node_name(node), node_hash)
  collect_children(node, node_hash)
  collect_attributes(node, node_hash)
  strip_whitespace_content(node_hash)
  hash
end