ManuParra
ManuParra

Reputation: 1531

Parse XML SOAP response with Python

I want parse this response from SOAP and extract text between <LoginResult> :

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
     <soap:Body>
      <LoginResponse xmlns="http://tempuri.org/wsSalesQuotation/Service1">
        <LoginResult>45eeadF43423KKmP33</LoginResult>
      </LoginResponse>
     </soap:Body>
</soap:Envelope>

How I can do it using XML Python Libs?

Upvotes: 4

Views: 23249

Answers (1)

Gjordis
Gjordis

Reputation: 2550

import xml.etree.ElementTree as ET
tree = ET.parse('soap.xml')    

print tree.find('.//{http://tempuri.org/wsSalesQuotation/Service1}LoginResult').text


>>45eeadF43423KKmP33

instead of print, do something useful to it.

Upvotes: 10

Related Questions