module MultiXml::Parsers::Libxml2Parser

def each_attr(*args)

def each_attr(*args)
  raise NotImplementedError, "inheritor should define #{__method__}"
end

def each_child(*args)

def each_child(*args)
  raise NotImplementedError, "inheritor should define #{__method__}"
end

def node_name(*args)

def node_name(*args)
  raise NotImplementedError, "inheritor should define #{__method__}"
end

def node_to_hash(node, hash={})

Hash to merge the converted element into.
hash::

The XML node object to convert to a hash.
node::

Convert XML document to hash
:nodoc:
def node_to_hash(node, hash={})
  node_hash = {MultiXml::CONTENT_ROOT => ''}
  name = node_name(node)
  # Insert node hash into parent hash correctly.
  case hash[name]
    when Array then hash[name] << node_hash
    when Hash  then hash[name] = [hash[name], node_hash]
    when nil   then hash[name] = node_hash
  end
  # Handle child elements
  each_child(node) do |c|
    if c.element?
      node_to_hash(c, node_hash)
    elsif c.text? || c.cdata?
      node_hash[MultiXml::CONTENT_ROOT] << c.content
    end
  end
  # Remove content node if it is empty
  if node_hash[MultiXml::CONTENT_ROOT].strip.empty?
    node_hash.delete(MultiXml::CONTENT_ROOT)
  end
  # Handle attributes
  each_attr(node) do |a|
    key = node_name(a)
    node_hash[key] = if v = node_hash[key]
                       [a.value, v]
                     else
                       a.value
                     end
  end
  hash
end

def parse(xml)

XML Document IO to parse
xml::
Parse an XML Document IO into a simple hash.
def parse(xml)
  raise NotImplementedError, "inheritor should define #{__method__}"
end