Method: CoreLibrary::XmlHelper.add_array_as_subelement

Defined in:
lib/apimatic-core/utilities/xml_helper.rb

.add_array_as_subelement(doc, root, item_name, items, wrapping_element_name: nil, datetime_format: nil) ⇒ Object

Adds array as a sub-element.

Parameters:

  • doc (Nokogiri::XML::Document)

    Document to add the hash to.

  • root (REXML::Element)

    Root element of the XML to add the attribute to.

  • item_name (String)

    Individual array item names.

  • items (Array)

    Array of items.

  • wrapping_element_name (String) (defaults to: nil)

    Main array item name.

  • datetime_format (CoreLibrary::DateTimeFormat) (defaults to: nil)

    The format to convert the date time into.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/apimatic-core/utilities/xml_helper.rb', line 83

def add_array_as_subelement(doc, root, item_name, items,
                            wrapping_element_name: nil,
                            datetime_format: nil)
  return if items.nil?

  if wrapping_element_name.nil?
    parent = root
  else
    parent = doc.create_element(wrapping_element_name)
    root.add_child(parent)
  end

  items.each do |item|
    add_as_subelement(doc, parent, item_name, item,
                      datetime_format: datetime_format)
  end
end