Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse XML SOAP response with Python

Tags:

python

soap

xml

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?

like image 872
ManuParra Avatar asked Oct 28 '25 09:10

ManuParra


1 Answers

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.

like image 60
Gjordis Avatar answered Oct 30 '25 00:10

Gjordis