Module: LibXML::Conversions::Node

Includes:
NodeHash
Defined in:
lib/xml_mini/libxml.rb

Constant Summary

Constants included from NodeHash

NodeHash::CONTENT_ROOT

Instance Method Summary collapse

Methods included from NodeHash

#handle_child_element, #insert_node_hash_into_parent, #remove_blank_content_node

Instance Method Details

#to_hash(hash = {}) ⇒ Object

Convert XML document to hash

hash

Hash to merge the converted element into.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/xml_mini/libxml.rb', line 39

def to_hash(hash={})
  node_hash = {}

  # Insert node hash into parent hash correctly.
  insert_node_hash_into_parent(hash, name, node_hash)

  # Handle child elements
  each_child do |child|
    handle_child_element(child, node_hash)
  end

  # Remove content node if it is blank
  remove_blank_content_node node_hash

  # Handle attributes
  each_attr { |a| node_hash[a.name] = a.value }

  hash
end