Search code examples
rubyxmlxml-parsingnokogirisavon

Searching savon response as nokogiri document returns an empty array


I try to parse savon's response as nokokiri document

c = Savon.client(wsdl: 'http://test.fedresurs.ru/MessageService/WebService.svc?wsdl', digest_auth: ['demowebuser', 'Ax!761BN'], namespace: "http://tempuri.org/", namespace_identifier: :tem, log: true)
r = c.call(:get_trade_messages, message: {'tem:startFrom' => DateTime.now-1})
r.doc.search("TradePlace")

and it returns an empty array.

What I'm doing wrong? May be I should deal somehow with namespaces? But, how?. Examples, that I found in nokogiri documentation use Xpath, not search. And even with Xpath it returns an empty array.

XML-response:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <GetTradeMessagesResponse xmlns="http://tempuri.org/">
         <GetTradeMessagesResult>
            <TradePlace INN="7606055642" Name="Первая электронная площадка " Site="1torgi.ru " OwnerName="ООО &quot;Промтех&quot;">
               <TradeList>
                  <Trade ID_External="ЗКОФЦП-17136" ID_EFRSB="653476">
                     <MessageList>
                        <TradeMessage ID="4851134"/>
                        <TradeMessage ID="4851135"/>
                     </MessageList>
                  </Trade>
               </TradeList>
            </TradePlace>
         </GetTradeMessagesResult>
      </GetTradeMessagesResponse>
   </s:Body>
</s:Envelope>

Solution

  • As I expected the answer was in namespace, code below works fine:

    r.doc.search("a|TradePlace", {"a" => "http://tempuri.org/"})