+ Start a Discussion
Madhusudan Singh 15Madhusudan Singh 15 

Not able to Parse XML

Hi All,

I am trying to parse below XML to get value of <state>RUNNING</state>. But it is giving null. I am using system.debug(document.getRootElement().getChildElement('return', null));

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
   <env:Header />
   <env:Body>
      <ns2:getOutboundCampaignResponse xmlns:ns2="http://service.admin.ws.five9.com/">
         <return>
            <description>1 - 14 Days Past Due</description>
            <mode>ADVANCED</mode>
            <name>Arrangements 1-14 TEST</name>
            <profileName>Arrangements</profileName>
            <state>RUNNING</state>
            <trainingMode>false</trainingMode>
            <type>OUTBOUND</type>
            <autoRecord>true</autoRecord>
            <callWrapup>
               <enabled>false</enabled>
            </callWrapup>
            <ftpHost />
            <ftpPassword />
            <ftpUser />
            <recordingNameAsSid>false</recordingNameAsSid>
            <useFtp>false</useFtp>
            <analyzeLevel>20</analyzeLevel>
            <CRMRedialTimeout>
               <days>0</days>
               <hours>1</hours>
               <minutes>0</minutes>
               <seconds>0</seconds>
            </CRMRedialTimeout>
            <dnisAsAni>false</dnisAsAni>
            <enableListDialingRatios>false</enableListDialingRatios>
            <listDialingMode>LIST_PENETRATION</listDialingMode>
            <noOutOfNumbersAlert>false</noOutOfNumbersAlert>
            <stateDialingRule>FOLLOW_STATE_RESTRICTIONS</stateDialingRule>
            <timeZoneAssignment>INHERIT_DOMAIN_SETTINGS</timeZoneAssignment>
            <actionOnAnswerMachine>
               <actionType>DROP_CALL</actionType>
            </actionOnAnswerMachine>
            <actionOnQueueExpiration>
               <actionType>DROP_CALL</actionType>
            </actionOnQueueExpiration>
            <callAnalysisMode>FAX_AND_ANSWERING_MACHINE</callAnalysisMode>
            <callsAgentRatio>1.0</callsAgentRatio>
            <dialNumberOnTimeout>true</dialNumberOnTimeout>
            <dialingMode>PROGRESSIVE</dialingMode>
            <dialingPriority>3</dialingPriority>
            <dialingRatio>50</dialingRatio>
            <distributionAlgorithm>MinHandleTime</distributionAlgorithm>
            <distributionTimeFrame>minutes30</distributionTimeFrame>
            <limitPreviewTime>true</limitPreviewTime>
            <maxDroppedCallsPercentage>3.0</maxDroppedCallsPercentage>
            <maxPreviewTime>
               <days>0</days>
               <hours>0</hours>
               <minutes>2</minutes>
               <seconds>0</seconds>
            </maxPreviewTime>
            <maxQueueTime>
               <days>0</days>
               <hours>0</hours>
               <minutes>0</minutes>
               <seconds>1</seconds>
            </maxQueueTime>
            <monitorDroppedCalls>true</monitorDroppedCalls>
            <previewDialImmediately>false</previewDialImmediately>
            <useTelemarketingMaxQueTimeEq1>false</useTelemarketingMaxQueTimeEq1>
         </return>
      </ns2:getOutboundCampaignResponse>
   </env:Body>
</env:Envelope>

Please help

Regards
Madhusudan Singh
pconpcon
It's a little more complicated than tha
 
String bodyNS = 'http://schemas.xmlsoap.org/soap/envelope/';
String outboundNS = 'http://service.admin.ws.five9.com/';

Dom.Document doc = new Dom.Document();
doc.load(xmlString);

String value = doc.getRootElement()
    .getChildElement('Body', bodyNS)
    .getChildElement('getOutboundCampaignResponse', outboundNS)
    .getChildElement('return', null)
    .getChildElement('state', null)
    .getText();

NOTE: When adding code please use the "Add a code sample" button (icon <>) to increase readability and make it easier to reference.