'Parsing Cisco Call Policy XML with Modern XML Python Module

Hello Ive searched and tried to do this myself but I need help.

Cisco Unified Communications Manager has the ability to route calls via External Call Control, this is done via XML POSTs and Responses from a Web Server. AKA CURRI https://developer.cisco.com/site/curri/

Im trying to parse the following XML that is posted to my web service (Flask). I need the AttributeID and AttributeValue in a dictionary would be lovely but I'd settle with some help getting the two values alone.

Sometimes the post will have all of these AttributeIDs and sometimes not so I just need a dictionary with whatever is provided and I can check if the key:value exists later down the script.

<?xml version="1.0" encoding="UTF-8"?>
<Request
    xmlns="urn:oasis:names:tc:xacml:2.0:context:schema:os">
    <Subject SubjectCategory="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject">
        <Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:subject:role-id"
DataType="http://www.w3.org/2001/XMLSchema#string" Issuer="requestor">
            <AttributeValue>CISCO:UC:UCMPolicy</AttributeValue>
        </Attribute>
        <Attribute AttributeId="urn:Cisco:uc:1.0:callingnumber"
DataType="http://www.w3.org/2001/XMLSchema#string">
            <AttributeValue>+12125551212</AttributeValue>
        </Attribute>
        <Attribute AttributeId="urn:Cisco:uc:1.0:callednumber"
DataType="http://www.w3.org/2001/XMLSchema#string">
            <AttributeValue>+12125551313</AttributeValue>
        </Attribute>
        <Attribute AttributeId="urn:Cisco:uc:1.0:transformedcgpn"
DataType="http://www.w3.org/2001/XMLSchema#string">
            <AttributeValue>+12125551212</AttributeValue>
        </Attribute>
        <Attribute AttributeId="urn:Cisco:uc:1.0:transformedcdpn"
DataType="http://www.w3.org/2001/XMLSchema#string">
            <AttributeValue>+12125551313</AttributeValue>
        </Attribute>
        <Attribute AttributeId="urn:Cisco:uc:1.0:callingdevicename" DataType="http://www.w3.org/2001/XMLSchema#string">
            <AttributeValue>PHONEMACABCED01</AttributeValue>
        </Attribute>
    </Subject>
    <Resource>
        <Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id"
DataType="http://www.w3.org/2001/XMLSchema#anyURI">
            <AttributeValue>CISCO:UC:VoiceOrVideoCall</AttributeValue>
        </Attribute>
    </Resource>
    <Action>
        <Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id"
DataType="http://www.w3.org/2001/XMLSchema#anyURI">
            <AttributeValue>any</AttributeValue>
        </Attribute>
    </Action>
    <Environment>
        <Attribute AttributeId="urn:Cisco:uc:1.0:triggerpointtype"
DataType="http://www.w3.org/2001/XMLSchema#string">
            <AttributeValue>directorynumber</AttributeValue>
        </Attribute>
    </Environment>
</Request>

There is an example of a Crude extractor but this uses Python 2 code and older modules that I would rather use lmxl or ElementTree.

https://github.com/gve-sw/Route-CUCM-calls-by-O365-calendar-with-CURRI/blob/master/saxXacmlHandler.py

End result would be a dictionary with key:values.

"{urn:Cisco:uc:1.0:callingnumber":"+12125551212", "urn:Cisco:uc:1.0:callednumber":"+12125551313"}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source