1

I have the below XML document I am trying to parse. I just need to grab one node from the document. I need to get the serviceProfile text. I'm banging my head against the desk here... I am new to Python.

<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <ns:getUserResponse
            xmlns:ns="http://www.cisco.com/AXL/API/11.5">
            <return>
                <user uuid="{blbhbl-bhblb-kbhb}">
                    <firstName>fname</firstName>
                    <displayName>fname lname</displayName>
                    <middleName/>
                    <lastName>lname</lastName>
                    <userid>wooty</userid>
                    <password/>
                    <pin/>
                    <mailid>[email protected]</mailid>
                    <department/>
                    <manager/>
                    <userLocale />
                    <associatedDevices/>
                    <primaryExtension/>
                    <associatedPc/>
                    <enableCti>false</enableCti>
                    <digestCredentials/>
                    <phoneProfiles/>
                    <defaultProfile/>
                    <presenceGroupName uuid="{sdsds-sdsds-sdsdsd-sdsdsd-sdsd}">Standard Presence group</presenceGroupName>
                    <subscribeCallingSearchSpaceName/>
                    <enableMobility>false</enableMobility>
                    <enableMobileVoiceAccess>false</enableMobileVoiceAccess>
                    <maxDeskPickupWaitTime>10000</maxDeskPickupWaitTime>
                    <remoteDestinationLimit>4</remoteDestinationLimit>
                    <associatedRemoteDestinationProfiles/>
                    <associatedTodAccess/>
                    <status>1</status>
                    <enableEmcc>false</enableEmcc>
                    <associatedCapfProfiles/>
                    <ctiControlledDeviceProfiles/>
                    <patternPrecedence />
                    <numericUserId />
                    <mlppPassword />
                    <customUserFields/>
                    <homeCluster>true</homeCluster>
                    <imAndPresenceEnable>true</imAndPresenceEnable>
                    <serviceProfile uuid="{dsdsdsd-sdsdsd-sdsd-sdsds-sdsds}">1 IM Presence Only</serviceProfile>
                    <lineAppearanceAssociationForPresences/>
                    <directoryUri>[email protected]</directoryUri>
                    <telephoneNumber>555-555-5555</telephoneNumber>
                    <title/>
                    <mobileNumber/>
                    <homeNumber/>
                    <pagerNumber/>
                    <extensionsInfo/>
                    <selfService />
                    <userProfile/>
                    <calendarPresence>false</calendarPresence>
                    <ldapDirectoryName uuid="{sdsd-sdsdsd-sdsds-sdsds}">someinfo</ldapDirectoryName>
                    <userIdentity>[email protected]</userIdentity>
                    <nameDialing>blehWoot</nameDialing>
                    <ipccExtension/>
                    <convertUserAccount uuid="{sdsd-sdsdsd-sdsds-sdsds}">someinfo</convertUserAccount>
                    <enableUserToHostConferenceNow>false</enableUserToHostConferenceNow>
                    <attendeesAccessCode/>
                </user>
            </return>
        </ns:getUserResponse>
    </soapenv:Body>
</soapenv:Envelope>
3
  • 2
    Have you tried something like root.find(".//serviceProfile").text (with root being the root element of your document (.getroot() on the tree or fromstring() parsing the XML from a string))? Consider adding a Minimal, Complete, and Verifiable example. Commented Jul 11, 2017 at 20:49
  • @danielHaley Thank you so much for that suggestion. this "root.find(".//serviceProfile").text" worked like a champ. My apologies on the MCVE requirements. Thanks again for your help! Commented Jul 12, 2017 at 12:59
  • 2
    You're welcome. Consider adding an answer with what you ended up using and accepting it. Commented Jul 13, 2017 at 17:42

1 Answer 1

3

Based on @danielHaley suggestions i created the following code to retrieve the node.

#read XML response and get service profile
tree = ET.ElementTree(ET.fromstring(response.content))
root = tree.getroot()

serviceprofile = root.find(".//serviceProfile").text 

Worked great. thank you so much for your help.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.