2016-06-20 41 views
0

我從下面的http調用中獲得響應。如何從python中的字符串獲得完整的xml

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://xxx.abc.in"><SOAP-ENV:Body><ns1:LoginResponse><return><SessionID>abc12345</SessionID><ResponseCode>0</ResponseCode><ResponseMessage>Successful</ResponseMessage></return></ns1:LoginResponse></SOAP-ENV:Body></SOAP-ENV:Envelope> 

現在既然這是字符串,我不能做一個XML差異。 當嘗試使用ElementTree的將其轉換成XML,我得到的只是根

tree = etree.fromstring(responseJson) 

結果:

<Element '{http://schemas.xmlsoap.org/soap/envelope/}Envelope' at 0x3414c90> 

請建議如何extact完整的XML(而無需將其保存爲一個文件) 。我是新來個XML,所以甚至不知道我在做正確的操作

回答

0

您可以使用索引,甚至功能,如findalliter,一個小例子下面有關如何迭代的<return>

for item in tree[0][0][0]: 
    print item 
內容
相關問題