Created
September 14, 2016 21:36
-
-
Save guoqiao/bd028f9492ea8b111acf08ccc5e3bc7e to your computer and use it in GitHub Desktop.
Extract element with namescape from xml by Python xml module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from xml.etree import ElementTree as ET | |
for prefix, uri in NAMESPACES.items(): | |
ET.register_namespace(prefix, uri) | |
root_xml_element = ET.fromstring(xml) | |
token_xml_element = root_xml_element.find( | |
'soap:Body', namespaces=NAMESPACES | |
).find( | |
'wst:RequestSecurityTokenResponseCollection', namespaces=NAMESPACES | |
).find( | |
'wst:RequestSecurityTokenResponse', namespaces=NAMESPACES | |
).find( | |
'wst:RequestedSecurityToken', namespaces=NAMESPACES | |
).find( | |
'saml2:Assertion', namespaces=NAMESPACES | |
) | |
token_xml = ET.tostring(token_xml_element) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment