Class: Patentscope::WebserviceSoapStripper

Inherits:
Object
  • Object
show all
Defined in:
lib/patentscope/webservice_soap_stripper.rb

Instance Method Summary collapse

Instance Method Details

#strip_envelope(response, operation) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/patentscope/webservice_soap_stripper.rb', line 5

def strip_envelope(response, operation)
  case operation
  when :getAvailableDocuments
    result_tag = 'getAvailableDocumentsResponse'
  when :getDocumentContent
    result_tag = 'getDocumentContentResponse'
  when :getDocumentOcrContent
    result_tag = 'getDocumentOcrContentResponse'
  when :getIASR
    result_tag = 'getIASRResponse'
  when :getDocumentTableOfContents
    result_tag = 'getDocumentTableOfContentsResponse'
  when :getDocumentContentPage
    result_tag = 'getDocumentContentPageResponse'
  end

  doc = Nokogiri::XML(response)
  stripped_response = doc.xpath("//iasr:#{result_tag}", 'iasr' => "http://www.wipo.org/wsdl/ps").children

  # add back the XML declaration to the XML with a namespace
  stripped_response_with_declaration = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
    xml.send(result_tag, "xmlns" => "http://www.wipo.org/wsdl/ps") do
      xml.parent << stripped_response
    end
  end.to_xml

  stripped_response_with_declaration
end