php用ns解析soap响应

php用ns解析soap响应,soap,xml-parsing,Soap,Xml Parsing,我有以下soap响应 <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"

我有以下soap响应

<?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
                       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <SOAP-ENV:Body>
    <ns0:READResponse xmlns:ns0="/PELTT01">
      <ns0:st_flag>0</ns0:st_flag>
      <ns0:st_title></ns0:st_title>
      <ns0:pod_date></ns0:pod_date>
      <ns0:pod_time></ns0:pod_time>
      <ns0:pod_name></ns0:pod_name>
      <ns0:web_status>
        <ns0:web_date>date1</ns0:web_date>
        <ns0:web_time>time1</ns0:web_time>
        <ns0:web_station>station1</ns0:web_station>
        <ns0:web_status_title>title1</ns0:web_status_title>
      </ns0:web_status>
      <ns0:web_status>
        <ns0:web_date>date2</ns0:web_date>
        <ns0:web_time>time2</ns0:web_time>
        <ns0:web_station>station2</ns0:web_station>
        <ns0:web_status_title>title2</ns0:web_status_title>
      </ns0:web_status>
      ...
      ...
 <ns0:web_status_counter>5</ns0:web_status_counter>
</ns0:READResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
试试2

有人能帮我解析这个soap响应吗

<?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
                       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <SOAP-ENV:Body>
    <ns0:READResponse xmlns:ns0="/PELTT01">
      <ns0:st_flag>0</ns0:st_flag>
      <ns0:st_title></ns0:st_title>
      <ns0:pod_date></ns0:pod_date>
      <ns0:pod_time></ns0:pod_time>
      <ns0:pod_name></ns0:pod_name>
      <ns0:web_status>
        <ns0:web_date>date1</ns0:web_date>
        <ns0:web_time>time1</ns0:web_time>
        <ns0:web_station>station1</ns0:web_station>
        <ns0:web_status_title>title1</ns0:web_status_title>
      </ns0:web_status>
      <ns0:web_status>
        <ns0:web_date>date2</ns0:web_date>
        <ns0:web_time>time2</ns0:web_time>
        <ns0:web_station>station2</ns0:web_station>
        <ns0:web_status_title>title2</ns0:web_status_title>
      </ns0:web_status>
      ...
      ...
 <ns0:web_status_counter>5</ns0:web_status_counter>
</ns0:READResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

感谢您的任何帮助

如果我理解正确,您正在寻找与您的Try 2相近的产品:

$dom->loadXML($xml_response);#note: NOT just "load"
$xpath = new DOMXPath($dom);
$xpath->registerNamespace("ns0", "/PELTT01");
$web_status = $xpath->query('//ns0:web_status');

foreach ($web_status as $wb)
{
    $cn = $wb->childNodes;
    foreach ($cn as $c){
        echo trim($c->textContent);
        }
}
输出:

        date1
        time1
        station1
        title1
      
        date2
        time2
        station2
        title2
      
        date1
        time1
        station1
        title1
      
        date2
        time2
        station2
        title2