我如何通过PHP解析xml以下?

时间:2017-09-22 11:04:10

标签: php web-services web

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <ns0:GetListBy_QualificationResponse xmlns:ns0="urn:WS_CTM_People_ICEVA">
         <ns0:getListValues>
            <ns0:Person_ID>PPL000000301739</ns0:Person_ID>
            <ns0:Submitter>soehler</ns0:Submitter>
            <ns0:Profile_Status>Enabled</ns0:Profile_Status>
            <ns0:Locale2>en_US</ns0:Locale2>
            <ns0:VIP>No</ns0:VIP>
            <ns0:Client_Sensitivity>Standard</ns0:Client_Sensitivity>
         </ns0:getListValues>
      </ns0:GetListBy_QualificationResponse>
   </soapenv:Body>
</soapenv:Envelope>

1 个答案:

答案 0 :(得分:0)

使用Simple HTML Dom课程。例如:

include('simple_html_dom.php');

$xml = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <ns0:GetListBy_QualificationResponse xmlns:ns0="urn:WS_CTM_People_ICEVA">
         <ns0:getListValues>
            <ns0:Person_ID>PPL000000301739</ns0:Person_ID>
            <ns0:Submitter>soehler</ns0:Submitter>
            <ns0:Profile_Status>Enabled</ns0:Profile_Status>
            <ns0:Locale2>en_US</ns0:Locale2>
            <ns0:VIP>No</ns0:VIP>
            <ns0:Client_Sensitivity>Standard</ns0:Client_Sensitivity>
         </ns0:getListValues>
      </ns0:GetListBy_QualificationResponse>
   </soapenv:Body>
</soapenv:Envelope>';

$xml = str_get_html($xml);
print_r( $xml );

读取课程文档并从$xml变量中提取数据。