Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python使用SOAP名称空间解析XML_Python_Xml_Soap_Elementtree - Fatal编程技术网

Python使用SOAP名称空间解析XML

Python使用SOAP名称空间解析XML,python,xml,soap,elementtree,Python,Xml,Soap,Elementtree,如何使用名称空间分析python XML输出: <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

如何使用名称空间分析python XML输出:

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
    <ns1:searchResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://configuration.api.sitescope.mercury.com">
        <searchReturn href="#id0"/>
    </ns1:searchResponse>
    <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:Map" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://xml.apache.org/xml-soap">
        <item>
            <key xsi:type="soapenc:string">test_sis_path_delimiter_www.google.com:443 on server www.google.com</key>
            <value xsi:type="soapenc:string">Group</value>
        </item>
    </multiRef>
</soapenv:Body>

在服务器www.google.com上测试路径分隔符www.google.com:443
团体

我需要得到关键和价值。
谢谢

对于解析XML,可以使用
BeautifulSoup
。示例如下:

data = """<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
    <ns1:searchResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://configuration.api.sitescope.mercury.com">
        <searchReturn href="#id0"/>
    </ns1:searchResponse>
    <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:Map" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://xml.apache.org/xml-soap">
        <item>
            <key xsi:type="soapenc:string">test_sis_path_delimiter_www.google.com:443 on server www.google.com</key>
            <value xsi:type="soapenc:string">Group</value>
        </item>
    </multiRef>
</soapenv:Body>"""

from bs4 import BeautifulSoup

soup = BeautifulSoup(data, 'xml')

print(soup.key.text)
print(soup.value.text)
test_sis_path_delimiter_www.google.com:443 on server www.google.com
Group