I am trying to obtain the value of 2 elements (Result and AuthenticationKey)from this XML. The <s:Envelope>
syntax is throwing me off.
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<AuthenticateResponse xmlns="http://remote.Services">
<AuthenticateResult xmlns:a="http://schemas.datacontract.org/2004/07/remote.Services.Api.DataContracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<AdditionalInfo i:nil="true"/>
<ErrorMessage i:nil="true"/>
<ErrorMessageId i:nil="true"/>
<ErrorMessages i:nil="true" xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
<InternalId>0</InternalId>
<RecordsAffected>0</RecordsAffected>
<Result>true</Result>
<WarningMessages i:nil="true" xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
<a:AuthenticationKey>SUPERSECRETTOKEN</a:AuthenticationKey>
<a:UserGrpId>YYY</a:UserGrpId>
<a:UserId>XXX</a:UserId>
</AuthenticateResult>
</AuthenticateResponse>
</s:Body>
</s:Envelope>
Here is the relevant line of code that is returning a None. Both lines of code are returning a None.
I tried to use the code from another question on stackoverflow, but I am not sure on how to introduce the namespaces in the find method for this particular xml.
tree = ElementTree.fromstring(resp.text)
token = tree.find("AuthenticateResponse") #Option1
token = tree.find("Envelope/Body/AuthenticateResponse/AuthenticateResult/AuthenticationKey") #Option2
print token