Module: Vindicia::XMLBuilder

Included in:
SoapClient, SoapObject
Defined in:
lib/vindicia.rb

Instance Method Summary collapse

Instance Method Details

#build_array_xml(xml, name, type, value) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/vindicia.rb', line 142

def build_array_xml(xml, name, type, value)
  attrs = {
    "xmlns:enc" => "http://schemas.xmlsoap.org/soap/encoding/",
    "xsi:type" => "enc:Array",
    "enc:arrayType" => "vin:#{name}[#{value.size}]"
  }
  xml.tag!(name, attrs) do |x|
    value.each do |val|
      build_tag_xml(x, 'item', type, val)
    end
  end
end

#build_tag_xml(xml, name, type, value) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/vindicia.rb', line 155

def build_tag_xml(xml, name, type, value)
  case value
  when Hash
    Vindicia.class(type).new(value).build(xml, name)
  when SoapObject
    value.build(xml, name)
  when NilClass
    xml.tag!(name, value, {"xsi:nil" => true})
  else
    type = type.sub(/^tns/,'vin')
    # format dates/times with full timestamp
    value = value.to_time.iso8601 if value.respond_to?(:to_time) && type == 'xsd:dateTime'
    xml.tag!(name, value, {"xsi:type" => type})
  end
end

#build_xml(xml, name, type, value) ⇒ Object



134
135
136
137
138
139
140
# File 'lib/vindicia.rb', line 134

def build_xml(xml, name, type, value)
  if value.kind_of? Array
    build_array_xml(xml, name, type, value)
  else
    build_tag_xml(xml, name, type, value)
  end
end