使用 Python 解析 XML SOAP 响应 [英] Parse XML SOAP response with Python
本文介绍了使用 Python 解析 XML SOAP 响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从 SOAP 解析这个响应并提取
之间的文本:
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>
我如何使用 XML Python 库来实现?
How I can do it using XML Python Libs?
推荐答案
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.
这篇关于使用 Python 解析 XML SOAP 响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文