繁体   English   中英

Python解析XML响应

[英]Python Parsing XML Response

我有一个SOAP响应,我正在尝试用ElementTree解析

    doc = ET.parse(response_xml)
    for cust in doc.findall('.//{http://www.starstandards.org/webservices/2005/10/transport}Content'):
        custnumber = cust.findtext('{http://www.starstandards.org/webservices/2005/10/transport}CustomerNumber')
        custfname = cust.findtext('{http://www.starstandards.org/webservices/2005/10/transport}FirstName')
        custlname = cust.findtext('{http://www.starstandards.org/webservices/2005/10/transport}LastName')
    return custnumber, custfname, custlname  

我正在尝试从响应中获取信息,并且不断出现以下错误:

No such file or directory

在解析该文件之前,是否需要将response_xml保存到文件中? 为什么我不能只从内存中使用它?

ET.parse()需要一个文件名。 您可能要尝试使用ET.fromstring()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM