2012-07-14 3 views
0

을 구문 분석하는 방법 i를 follwing을 문자열을 가지고 내가 SOAP의 Respose

$xmlstring='<soap-env:envelope xmlns:ns1="http://back.com/" 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" 
      xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"> 
      <soap-env:header></soap-env:header> 
      <soap-env:body> 
       <ns1:createuserresponse> 
        <username>qqq_d481</username> 
        <password>sdfdssdfds</password> 
        <result> 
        <succeeded>true</succeeded> 
        <errorcode>0</errorcode> 
        <errortext></errortext> 
        </result> 
       </ns1:createuserresponse> 
      </soap-env:body> 
      </soap-env:envelope>'; 

어느 한 날을 제안 할 수 있습니다 ...이 문자열에서 사용자 이름과 암호를 분석 할 .. 문자열 위 는 SOAP 응답

입니다

하지만 난 Adavance에

$xmlstring='<soap-env:envelope> 
<soap-env:header></soap-env:header> 
<soap-env:body> 
    <ns1:createuserresponse> 
     <username>qqq_d481</username> 
     <password>sdfdssdfds</password> 
     <result> 
      <succeeded>true</succeeded> 
      <errorcode>0</errorcode> 
      <errortext></errortext> 
     </result> 
    </ns1:createuserresponse> 
</soap-env:body></soap-env:envelope>'; 



echo $xmltoparse= $xmlstring; 
$xml = simplexml_load_string($xmltoparse); 
print_r($xml); 

then it works fine 

감사를 사용하는 경우

+0

을 확인? 당신의 예제에서''my xml string ''을 파싱하기 때문에 – Anas

답변

0

아마 당신은 simple_xml_parser 대신 PHP5 Soap Client를 사용할 수 있습니다. How to parse SOAP XML?

0

당신이하고 싶은 것을 완전히 이해하고 있는지는 모르겠지만 어쩌면 이렇게 될지 모르십니까?

** 테스트되지 않은 코드 만

public function parseLoginResponse($loginResponse) 
{ 
    $match = array(
     'username' => 'username', 
     'password' => 'password', 
     'succeeded' => 'succeeeded', 
     'errortext' => 'errortext' 
    ); 

    $this->_match($match, $loginResponse); 

    return array(
     'user' => $this->username, 
     'pass' => $this->password, 
     'success' => $this->succeeded, 
     'error' => $this->errortext 
    ); 
} 
관련 문제