lib/ews/soap/builders/ews_builder.rb
# 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).
Build XML from a passed in Hash or Array in a specified format.
Build XML from a passed in Hash or Array in a specified format .
def build_xml!(elems)
      case elems.class.name
        when 'Hash'
          keys = elems.keys
          vals = elems.values
          raise "invalid input: #{elems}" if (keys.length > 1 && !vals.is_a?(Hash))
          vals            = vals.first.clone
          se              = vals.delete(:sub_elements)
          txt             = vals.delete(:text)
          xmlns_attribute = vals.delete(:xmlns_attribute)
          if keys.first == 'string'
            node = @nbuild.String(txt, vals) { |x| build_xml!(se) if se }
          else
            node = @nbuild.send(camel_case(keys.first), txt, vals) { |x| build_xml!(se) if se }
          end
          node.xmlns = NAMESPACES["xmlns:#{xmlns_attribute}"] if xmlns_attribute
        when 'Array'
          elems.each { |e| build_xml!(e) }
        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 raise "invalid input: #{elems}" if ( keys . length > 1 && ! vals . is_a? ( Hash ) ) vals = vals . first . clone se = vals . delete ( :sub_elements ) txt = vals . delete ( :text ) xmlns_attribute = vals . delete ( :xmlns_attribute ) if keys . first == 'string' node = @nbuild . String ( txt , vals ) { | x | build_xml! ( se ) if se } else node = @nbuild . send ( camel_case ( keys . first ) , txt , vals ) { | x | build_xml! ( se ) if se } end node . xmlns = NAMESPACES [ "xmlns:#{xmlns_attribute}" ] if xmlns_attribute when 'Array' elems . each { | e | build_xml! ( e ) } else raise "Unsupported type: #{elems.class.name}" end end
Build XML from a passed in Hash or Array in a specified format.
Build XML from a passed in Hash or Array in a specified format .
# Set node level namespace
elems
<not_specific>
<not_specific>
elems The elements to add to the Builder.
elems The elements to add to the Builder .