2012-09-03 5 views
0
여기

하는 API에서 내 XML 응답이되고있는 노드 읽기 위해 애 쓰고 :SimpleXML을

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

가 어떻게 상태 노드를 reaq 수 있습니까? 나는 많은 콤보를 시도했다 : 추한

  $getCertificateXMLResponse = simplexml_load_string($getCertificateXMLResponse); 

     echo $getCertificateXMLResponse->GetCertificateResponse->GetCertificateResult->ReturnValue->Status; 
+0

를 사용하여 SOAP PHP의 확장자를 그것을 할 수도 있습니다. –

답변

1

당신은 XPath는 함께 SOAP 요청을 처리 할 수 ​​

$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]; 
+0

내 방법이 효과가없는 이유를 말해 줄 수 있습니까? 그것은 SOAP이기 때문에 일반적인 XML 응답을 읽는 것보다 더 많은 것이 있습니까? 감사! –

+0

트리의 머리 부분에서 메서드를 시작하지 않았기 때문입니다. 예 : $ getCertificateXMLResponse-> children ("soap", true) -> Body-> children() -> GetCertificateResponse-> GetCertificateResult-> ReturnValue-> Status –

+0

원본 솔루션은 바로 작동합니다 나에게 충분하다. 입력 건배 –

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과 같은 것을 살펴보십시오.