简体   繁体   English

Python解析XML响应

[英]Python Parsing XML Response

I have a SOAP response which I am trying to parse with ElementTree 我有一个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  

I am trying to get the information out of the response and I keep getting the following error: 我正在尝试从响应中获取信息,并且不断出现以下错误:

No such file or directory

Does the response_xml need to be saved to a file before I can parse it? 在解析该文件之前,是否需要将response_xml保存到文件中? Why can't I just use it from memory? 为什么我不能只从内存中使用它?

ET.parse() needs a file name. ET.parse()需要一个文件名。 You might want to try ET.fromstring() instead. 您可能要尝试使用ET.fromstring()

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

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