0

Here is my XML response from an API:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <GetCertificateResponse xmlns="http://url.com">
      <GetCertificateResult>
        <ReturnValue xmlns="">
          <Status>Success</Status>
          <Message/>
          <CertificateNumber/>
          <URL/>
        </ReturnValue>
      </GetCertificateResult>
    </GetCertificateResponse>
  </soap:Body>
</soap:Envelope>

How can I reaq the status node? I've tried so many combos:

            $getCertificateXMLResponse = simplexml_load_string($getCertificateXMLResponse);

        echo  $getCertificateXMLResponse->GetCertificateResponse->GetCertificateResult->ReturnValue->Status;
4

2 回答 2

1

你也可以使用 Xpath

$xml = simplexml_load_string($soap, NULL, NULL, "http://schemas.xmlsoap.org/soap/envelope/");
$xml->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');

$result = $xml->xpath('//Status');
echo $result[0];
于 2012-09-03T11:40:46.987 回答
0

它......丑陋..但有效

$xml = new SimpleXMLElement(file_get_contents('a.xml'),0,false,'');
$namespaces = $xml->getDocNamespaces(true);
$xml->registerXPathNamespace('empty', $namespaces['']);
$xml->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');
$status = array_shift($xml->xpath("soap:Body/empty:GetCertificateResponse/empty:GetCertificateResult/ReturnValue/Status"));
echo $status->asXML();

我很想看到更优雅的解决方案。

确实看看像nusoap这样的东西。

于 2012-09-03T11:32:52.443 回答