从xml删除名称空间

时间:2019-02-26 12:05:53

标签: python xml parsing

我想从python中的xml中删除名称空间ns :.下面是我正在获取的示例。当前我正在使用元素树进行解析

 <?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP- 
 ENV="http://schemas.xmlsoap.org/soap/envelope/" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"><SOAP-ENV:Body> 
 <ns:Verify_Output xmlns:ns="http://siebel.com/CustomUI"> 
 <ns:Error_spcCode>0</ns:Error_spcCode><ns:Error_spcMessage> 
 </ns:Error_spcMessage> 
 <ns:Integration_spcId>1515463369</ns:Integration_spcId> 
 </ns:Verify_Output>
 </SOAP-ENV:Body>
 </SOAP-ENV:Envelope>     

我想要此输出并想获取Error_spcCode的值

 import xml.etree.ElementTree as ET 
 tree = ET.fromstring(r.text)


 <SOAP-ENV:Envelope xmlns:SOAP- 
     ENV="http://schemas.xmlsoap.org/soap/envelope/" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <SOAP-ENV:Body>
    <ns:Verify_Output xmlns:ns="http://siebel.com/CustomUI">
     <Error_spcCode>0</Error_spcCode>

     <Integration_spcId>1511111111</Integration_spcId>
    </ns:Verify_Output>
  </SOAP-ENV:Body> 
  </SOAP-ENV:Envelope>

0 个答案:

没有答案