Method: Soaspec::SoapHandler#value_from_path

Defined in:
lib/soaspec/exchange_handlers/soap_handler.rb

#value_from_path(response, path, attribute: nil) ⇒ String

Based on a exchange, return the value at the provided xpath If the path does not begin with a ‘/’, a ‘//’ is added to it

Parameters:

  • response (Savon::Response)
  • path (String)

    Xpath

  • attribute (String) (defaults to: nil)

    Generic attribute to find. Will override path

Returns:

  • (String)

    Value at Xpath

Raises:



180
181
182
183
184
185
186
# File 'lib/soaspec/exchange_handlers/soap_handler.rb', line 180

def value_from_path(response, path, attribute: nil)
  results = xpath_elements_for(response: response, xpath: path, attribute: attribute)
  raise NoElementAtPath, "No value at Xpath '#{path}' in XML #{response.doc}" if results.empty?
  return results.first.inner_text if attribute.nil?

  results.first.attributes[attribute].inner_text
end