Tôi đã thực hiện cuộc gọi xà phòng với Savon. Đây hoạt động tốt và cung cấp cho các phản ứng sau:Đọc phản hồi với Nokogiri từ cuộc gọi SOAP với Savon
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://
schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetTop10Response xmlns="http://www.kirupafx.com">
<GetTop10Result>
<string>string</string>
<string>string</string>
</GetTop10Result>
</GetTop10Response>
</soap:Body>
</soap:Envelope>
Bây giờ tôi muốn đưa tất cả các yếu tố chuỗi ra khỏi phản ứng. Nhưng Tôi không thể làm cho nó hoạt động.
def query(params=nil)
client = Savon::Client.new do
wsdl.document = "http://www.kirupafx.com/WebService/TopMovies.asmx?wsdl"
end
response = client.request :get_top10
if response.success?
xml = Nokogiri::XML(response.to_xml)
print "Until here oké!"
xml.search('//GetTop10Result').each do |result|
print "How are you Ruby?"
@result[result.at('string').inner_text] = result.at('string').inner_text
end
else
raise "Error!"
end
Nhưng anh ấy chưa bao giờ in đẹp "Làm thế nào bạn là Ruby?" Ai đó có thể giúp tôi không? Tôi đang làm gì sai?
Điều gì sẽ xảy ra khi bạn thay thế 'xml.search' bằng' xml.xpath'? – ScottJShea