2014-02-17 10 views
0

SOAP 호출을 수행하고 데이터를 XML로 반환합니다. 반환하는 XML에는 처리 방법을 알 수없는 마크 업이 있습니다. 나는 단지 모두 <web_get_debiteuren>이 필요합니다.PHP가 XML 파일에서 데이터를 가져 오는 중

php SimpleXMLElement (http://www.php.net/manual/en/simplexml.examples-basic.php)를 사용하려고 생각했습니다.

$xml = new SimpleXMLElement($result); 
echo $xml->soap; 

가 어떻게 모든 결과를 통해 XML 파일의 <web_get_debiteuren> 부분을 wals 할 수있을 것입니다 :하지만 이런 일을 할 수 아니에요? 아래

참조 XML은 :

<?xml version="1.0" encoding="windows-1250"?> 
<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> 
    <getdatawithoptionsresponse xmlns="urn:Afas.Profit.Services"> 
     <getdatawithoptionsresult> 
     <AfasGetConnector> 
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
      <xs:element name="AfasGetConnector"> 
       <xs:complexType> 
       <xs:choice maxOccurs="unbounded"> 
        <xs:element name="web_get_debiteuren"> 
        <xs:complexType> 
         <xs:sequence> 
         <xs:element name="Nummer_debiteur" type="xs:string" minOccurs="0"/> 
         <xs:element name="Naam_debiteur" type="xs:string" minOccurs="0"/> 
         <xs:element name="E-mail_werk" type="xs:string" minOccurs="0"/> 
         <xs:element name="Voornaam" type="xs:string" minOccurs="0"/> 
         <xs:element name="Achternaam" type="xs:string" minOccurs="0"/> 
         </xs:sequence> 
        </xs:complexType> 
        </xs:element> 
       </xs:choice> 
       </xs:complexType> 
      </xs:element> 
      </xs:schema> 
      <web_get_debiteuren> 
      <Nummer_debiteur>10000</Nummer_debiteur> 
      <Naam_debiteur>Test</Naam_debiteur> 
      <Voornaam>Hans</Voornaam> 
      <Achternaam>Klok</Achternaam> 
      </web_get_debiteuren> 
      <web_get_debiteuren> 
      <Nummer_debiteur>11000</Nummer_debiteur> 
      <Naam_debiteur>Sven</Naam_debiteur> 
      <E-mail_werk>[email protected]</E-mail_werk> 
      <Voornaam>Sven</Voornaam> 
      <Achternaam>Kramer</Achternaam> 
      </web_get_debiteuren> 
      <web_get_debiteuren> 
      <Nummer_debiteur>11001</Nummer_debiteur> 
      <Naam_debiteur>Ireen</Naam_debiteur> 
      <E-mail_werk>[email protected]</E-mail_werk> 
      <Voornaam>Ireen</Voornaam> 
      <Achternaam>Wust</Achternaam> 
      </web_get_debiteuren> 
     </AfasGetConnector> 
     </getdatawithoptionsresult> 
    </getdatawithoptionsresponse> 
    </soap:body> 
</soap:envelope> 
+0

비누를 사용하는 경우 반환은 객체/배열 형식이어야합니다. 어떻게 원시 XML을 얻고 있습니까? __getLastResponse()와 같은 디버그 함수 중 하나를 통해? –

+0

__getLastResponse()가 비어 있습니다. SOAP 서비스에서는 NTLM 인증이 필요하므로 결과는 cURL로 가져옵니다. 게시 한 XML은 SOAP 호출에서 반환되는 코드입니다. – Timo002

답변

0

당신은 xpath을 사용할 수 있습니다. 가능한 문제와 샘플 :

Using xpath on a PHP SimpleXML object, SOAP + namespaces (not working..) parse an XML with SimpleXML which has multiple namespaces

하지만 생각이 가능하면 SoapClient를 사용해야합니다 ..

+0

SoapClient는 아무 것도 반환하지 않습니다. SOAP 서비스에서는 NTLM 인증이 필요하므로 결과는 cURL로 가져옵니다. 게시 한 XML은 SOAP 호출에서 반환되는 코드입니다. xpath를 이해하는 데 어려움이 있지만 그것을 보아라! – Timo002

+0

당신은이 해결책을 시도해 볼 수 있습니다 - http://www.php.net/manual/en/soapclient.soapclient.php#97029 – Nostalgie

+0

나는이 수업을 사용했습니다, http://tcsoftware.net/blog/2011/08/php- soapclient-authentication /, 나는 생각한다. – Timo002

0

감사를 XPath를 사용 Nostalgie의 끝 부분에, 나는 일을 얻었다. 아래 코드를 참조하십시오

$response = simplexml_load_string($result ,NULL, NULL, "http://schemas.xmlsoap.org/soap/envelope/"); 

$response->registerXPathNamespace("site", "urn:Afas.Profit.Services"); 
$_res = $response->xpath('//site:AfasGetConnector'); 
#$_res = $_res->AfasGetConnector; 

foreach($_res[0]->web_get_debiteuren AS $deb){ 
    echo "Number: ".$deb->Nummer_debiteur."<br>"; 
} 

이 출력됩니다 :

Number: 10000 
Number: 11000 
Number: 11001 
Number: 11002 
Number: 11003 
Number: 11004 

고맙습니다!

관련 문제