def build_xml!(elems)
      case elems.class.name
      when 'Hash'
        keys = elems.keys
        vals = elems.values
        if(keys.length > 1 && !vals.is_a?(Hash))
          raise "invalid input: #{elems}"
        end
        vals = vals.first.clone
        se = vals.delete(:sub_elements)
        txt = vals.delete(:text)
        xmlns_attribute = vals.delete(:xmlns_attribute)

        node = @nbuild.send(camel_case(keys.first), txt, vals) {|x|
          build_xml!(se) if se
        }

        # Set node level namespace
        node.xmlns = NAMESPACES["xmlns:#{xmlns_attribute}"] if xmlns_attribute
      when 'Array'
        elems.each do |e|
          build_xml!(e)
        end
      else
        raise "Unsupported type: #{elems.class.name}"
      end
    end
def build_xml!(elems)
      case elems.class.name
      when 'Hash'
        keys = elems.keys
        vals = elems.values
        if(keys.length > 1 && !vals.is_a?(Hash))
          raise "invalid input: #{elems}"
        end
        vals = vals.first.clone
        se = vals.delete(:sub_elements)
        txt = vals.delete(:text)
        xmlns_attribute = vals.delete(:xmlns_attribute)

        node = @nbuild.send(camel_case(keys.first), txt, vals) {|x|
          build_xml!(se) if se
        }

        # Set node level namespace
        node.xmlns = NAMESPACES["xmlns:#{xmlns_attribute}"] if xmlns_attribute
      when 'Array'
        elems.each do |e|
          build_xml!(e)
        end
      else
        raise "Unsupported type: #{elems.class.name}"
      end
    end
Build XML from a passed in Hash or Array in a specified format.
 @param [Array,Hash] elems The elements to add to the Builder. They must
   be specified like so:

   !{:top =>
     { :xmlns => 'http://stonesthrow/soap',
       :sub_elements => [
         {:elem1 => {:text => 'inside'}},
         {:elem2 => {:text => 'inside2'}}
       ],
       :id => '3232', :tx_dd => 23, :asdf => 'turkey'
     }
   }
   or
   [ {:first => {:text => 'hello'}},
     {:second => {:text => 'world'}}
   ]

   NOTE: there are specialized keys for text (:text), child elements
   (:sub_elements) and namespaces (:xmlns).