Ich schreibe ein Ruby-Skript, um einen Postman-SOAP-POST-Aufruf zu machen, dann Nokogiri zu verwenden, um die XML-Antwort zu analysieren. Als ich um die vollen SOAP-Aufruf-Antwort von Postman, es in mein Editor kopieren und manuell den XML Körper nehmen und dekodieren und zu formatieren es online das folgende Nokogiri Skript erfolgreich zu verwenden, ich bin in der Lage:Arbeiten mit XML-Körper von Soap-Aufruf mit Nokogiri in Ruby
doc = Nokogiri::XML(File.open("response.xml"))
property_ids = []
doc.css('Property').each do |property|
puts "Property ID: #{property['PropertyId']}"
property_ids << property['PropertyId']
end
property_ids.each_with_index do |property_id, index|
puts "index: #{index}"
puts "property id: #{property_id}"
end
Wo ich laufen in das Problem ist, wenn ich im Script die Ruby-Schnipsel des Postman Anruf aufnehmen möchten:
require 'nokogiri'
require 'uri'
require 'net/http'
require 'openssl'
url = URI("https://esite.thelyndco.com/AmsiWeb/eDexWeb/esite/leasing.asmx")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(url)
request["content-type"] = 'application/soap+xml'
request["cache-control"] = 'no-cache'
request["postman-token"] = '916e3f3d-11ca-e8cf-2066-542b009a281d'
request.body = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">\r\n <soap12:Body>\r\n <GetPropertyList xmlns=\"http://tempuri.org/\">\r\n <UserID>updater</UserID>\r\n <Password>[password]</Password>\r\n <PortfolioName>[portfolio name]</PortfolioName>\r\n <XMLData> \r\n</XMLData>\r\n </GetPropertyList>\r\n </soap12:Body>\r\n</soap12:Envelope>"
response = http.request(request)
doc = Nokogiri::XML(response.body)
# doc = Nokogiri::XML(File.open("full-response.xml"))
# doc.at('GetPropertyListResponse').text
Was will ich mit dem SOAP-Umschlag die vollständige SOAP-Antwort ist, um zu tun und in der Lage, sie zu verarbeiten in mein Skript, ohne ausschneiden und einfügen zu müssen; manuell dekodieren und formatieren mit Online-XML-Formatierern.
Kommentiert sind ein paar Zeilen, die ich von Stack Overflow probiert habe. Ist es möglich, den XML-Körper mit Nokogiri zu entschlüsseln und zu formatieren oder den SOAP-Umschlag auszuwerten?
edit:
Durch die XML-Decodierung ich meine Einnahme:
<GetPropertyListResult><Properties><Property PropertyId="11A" PropertyName1="1111 Austin Hwy" PropertyName2="" PropertyAddrLine1="The 1111" PropertyAddrLine2="1111 Austin Highway" PropertyAddrLine3="" PropertyAddrLine4="" PropertyAddrCity="San Antonio" PropertyAddrState="TX" PropertyAddrZipCode="78209" PropertyAddrCountry="" PropertyAddrEmail="" RemitToAddrLine1="The 1111" RemitToAddrLine2="1111 Austin Highway" RemitToAddrLine3="" RemitToAddrLine4="" RemitToAddrCity="San Antonio" RemitToAddrState="TX" RemitToAddrZipCode="78209" RemitToAddrCountry="" LiveDate="2013-12-04T00:00:00" MgrOffPhoneNo="210-804-1100" MgrFaxNo="" MgrSalutation="" MgrFirstName="" MgrMiName="" MgrLastName="" MonthEndInProcess="N"><Amenity PropertyId="11A"
und Dekodieren es in die Nutzung dieser online XML decoder:
<GetPropertyListResult><Properties><Property PropertyId="11A" PropertyName1="1111 Austin Hwy" PropertyName2="" PropertyAddrLine1="The 1111" PropertyAddrLine2="1111 Austin Highway" PropertyAddrLine3="" PropertyAddrLine4="" PropertyAddrCity="San Antonio" PropertyAddrState="TX" PropertyAddrZipCode="78209" PropertyAddrCountry="" PropertyAddrEmail="" RemitToAddrLine1="The 1111" RemitToAddrLine2="1111 Austin Highway" RemitToAddrLine3="" RemitToAddrLine4="" RemitToAddrCity="San Antonio" RemitToAddrState="TX" RemitToAddrZipCode="78209" RemitToAddrCountry="" LiveDate="2013-12-04T00:00:00" MgrOffPhoneNo="210-804-1100" MgrFaxNo="" MgrSalutation="" MgrFirstName="" MgrMiName="" MgrLastName="" MonthEndInProcess="N"><Amenity PropertyId="11A"
dann durch eine XML formatter ausgeführt, so dass verschachtelte Elemente sind für die Lesbarkeit eingerückt.
Was die ‚decode‘ Verben tun und ‚format‘ bedeutet in diesem Fall? Was machst du eigentlich mit der Hand, die du mit dem Ruby-Code machen musst? –
@MichaelGaskill, bearbeitete Frage zur Klärung der XML-Decodierung und Formatierung. – phizzy