lib/soaspec/exchange_handlers/soap_handler.rb in soaspec-0.0.71 vs lib/soaspec/exchange_handlers/soap_handler.rb in soaspec-0.0.72
- old
+ new
@@ -145,24 +145,32 @@
body = response.body
body.extend Hashie::Extensions::DeepFind
!body.deep_find_all(expected).empty?
end
+ # Convert all XML nodes to lowercase
+ # @param [Nokogiri::XML::Document]
+ def convert_to_lower_case(xml_doc)
+ xml_doc.traverse do |node|
+ node.name = node.name.downcase if node.kind_of?(Nokogiri::XML::Element)
+ end
+ end
+
# Returns the value at the provided xpath
# @param [Savon::Response] response
# @param [String] xpath
# @param [String] attribute Generic attribute to find
# @return [String] Value inside element found through Xpath
def xpath_value_for(response: nil, xpath: nil, attribute: nil)
raise ArgumentError('response and xpath must be passed to method') unless response && xpath
- result =
- if Soaspec.strip_namespaces? && !xpath.include?(':')
- temp_doc = response.doc.dup
- temp_doc.remove_namespaces!
- temp_doc.at_xpath(xpath)
- else
- response.xpath(xpath).first # Note this is Savon's xpath method. Hence Nokogiri 'at_xpath' not used
- end
+ temp_doc = response.doc.dup
+ convert_to_lower_case(temp_doc) if convert_to_lower?
+ result = if Soaspec.strip_namespaces? && !xpath.include?(':')
+ temp_doc.remove_namespaces!
+ temp_doc.at_xpath(xpath)
+ else
+ temp_doc.at_xpath(xpath, temp_doc.collect_namespaces)
+ end
raise NoElementAtPath, "No value at Xpath '#{xpath}' in XML #{response.doc}" unless result
return result.inner_text if attribute.nil?
result.attributes[attribute].inner_text
end
\ No newline at end of file