Srinu Chilukuri
Srinu Chilukuri

Reputation: 93

How to read Soap XML Response using php?

I am using curl to execute soap call below is the Response of Soap XMl, How to read the content of dataText attribute data using php.

    <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
     <soapenv:Header/>
      <soapenv:Body>
       <ins:dataTransferResponseType xmlns:ins="insite:soapws:connectorn:v1">
        <ins:data>
         <dataText>
             <![CDATA[Buyer Name,Buyer Code,Supplier Name,Supplier Code,Account Name,Account 
           Code,Remit To Address Code,Work Order ID,Worker ID,Job Seeker ID,Worker Last Name,Worker 
           First Name,Site Code,Site Name,Business Unit Code,Business Unit Name,Time Sheet ID,Time 
           Sheet Status,Time Sheet Start Date,Time Sheet End Date,Time Sheet Submit Date/Time,Time 
           Sheet Approved Date,Time Entry Date,Cost Center Code,Cost Center Name,Task Code,Task 
          Name,General Ledger Account Code,Billable Per Diem,Billable Hours,Non-billable Hours,Total 
          Hours,Currency,Rate Category / UOM,Bill Rate Supplier,Pay Rate 
           AT&T,ABC,DFG,CNV1,AT&T,ABC,,CDGD2323,ASG6546,cdfgdf534,SEDSS,HGDTTD,30319 - ATLANTA,USA | 
          GA | ATLANTA,12121212,DIGITAL,ssss54343,Invoiced,12/22/2019,12/28/2019,12/23/2019 
          15:51,12/24/2019 15:37,12/23/2019,DL01,Distribution Line 01,Hours Worked,Hours 
            Worked,Default,0.00,8.00,0.00,8.00,USD,ST/Hr,79.41,77.51]]>
         </dataText>
       </ins:data>
     </ins:dataTransferResponseType>
    </soapenv:Body>
    </soapenv:Envelope>

Thanks in advance.

Upvotes: 0

Views: 106

Answers (1)

Micha&#235;l
Micha&#235;l

Reputation: 1130

$xml = '<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
     <soapenv:Header/>
      <soapenv:Body>
       <ins:dataTransferResponseType xmlns:ins="insite:soapws:connectorn:v1">
        <ins:data>
         <dataText>
             <![CDATA[Buyer Name,Buyer Code,Supplier Name,Supplier Code,Account Name,Account 
           Code,Remit To Address Code,Work Order ID,Worker ID,Job Seeker ID,Worker Last Name,Worker 
           First Name,Site Code,Site Name,Business Unit Code,Business Unit Name,Time Sheet ID,Time 
           Sheet Status,Time Sheet Start Date,Time Sheet End Date,Time Sheet Submit Date/Time,Time 
           Sheet Approved Date,Time Entry Date,Cost Center Code,Cost Center Name,Task Code,Task 
          Name,General Ledger Account Code,Billable Per Diem,Billable Hours,Non-billable Hours,Total 
          Hours,Currency,Rate Category / UOM,Bill Rate Supplier,Pay Rate 
           AT&T,ABC,DFG,CNV1,AT&T,ABC,,CDGD2323,ASG6546,cdfgdf534,SEDSS,HGDTTD,30319 - ATLANTA,USA | 
          GA | ATLANTA,12121212,DIGITAL,ssss54343,Invoiced,12/22/2019,12/28/2019,12/23/2019 
          15:51,12/24/2019 15:37,12/23/2019,DL01,Distribution Line 01,Hours Worked,Hours 
            Worked,Default,0.00,8.00,0.00,8.00,USD,ST/Hr,79.41,77.51]]>
         </dataText>
       </ins:data>
     </ins:dataTransferResponseType>
    </soapenv:Body>
    </soapenv:Envelope>';

$dom = new DOMDocument(); 
$dom->loadXML($xml);

if($dom->getElementsByTagName('dataText')->length)
{
     print_r($dom->getElementsByTagName('dataText')->item(0)->nodeValue);
}

Upvotes: 1

Related Questions