Method: Soaspec::WsdlGenerator#root_elements_for

Defined in:
lib/soaspec/wsdl_generator.rb

#root_elements_for(op_details) ⇒ Nokogiri::XML::NodeSet

Returns List of the root elements in the SOAP body.

Parameters:

  • op_details (Hash)

    Hash with details from WSDL for an operation

Returns:

  • (Nokogiri::XML::NodeSet)

    List of the root elements in the SOAP body



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/soaspec/wsdl_generator.rb', line 66

def root_elements_for(op_details)
  raise "'@wsdl_schemas' must be defined" if @wsdl_schemas.nil?

  root_element = @wsdl_schemas.at_xpath("//*[@name='#{op_details[:input]}']")
  raise 'Operation has no input defined' if root_element.nil?

  schema_namespace = root_element.namespace.prefix
  root_type = root_element['type']
  if root_type
    @wsdl_schemas.xpath("//*[@name='#{root_type.split(':').last}']//#{schema_namespace}:element")
  else
    return [] unless complex_type? root_element # Empty Array if there are no root elements

    complex_type = root_element.children.find { |c| c.name == 'complexType' }
    sequence = complex_type.children.find { |c| c.name == 'sequence' }
    sequence.xpath("#{schema_namespace}:element")
  end
end