Method: Soaspec::RestHandler#xpath_value_for
- Defined in:
- lib/soaspec/exchange_handlers/rest_handler.rb
#xpath_value_for(response: nil, xpath: nil, attribute: nil) ⇒ String
Returns the value at the provided xpath
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/soaspec/exchange_handlers/rest_handler.rb', line 246 def xpath_value_for(response: nil, xpath: nil, attribute: nil) raise ArgumentError unless response && xpath raise "Can't perform XPATH if response is not XML" unless Interpreter.response_type_for(response) == :xml result = if Soaspec.strip_namespaces? && !xpath.include?(':') temp_doc = Nokogiri.parse response.body temp_doc.remove_namespaces! temp_doc.xpath(xpath).first else Nokogiri.parse(response.body).xpath(xpath).first end raise NoElementAtPath, "No value at Xpath '#{xpath}'" unless result return result.inner_text if attribute.nil? result.attributes[attribute].inner_text end |