0

APIからのXML応答は次のとおりです。

<?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>

ステータスノードを取得するにはどうすればよいですか?私は非常に多くのコンボを試しました:

            $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 に答える