2012-07-14 63 views
0

我有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响应

但如果我使用

$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 

感谢Adavance

+0

你肯定你的榜样工作?因为你在你的例子中解析''我的xml字符串''' – Anas 2012-07-14 10:49:29

回答

0

也许你可以使用PHP5肥皂客户端,而不是像这里建议的simple_xml_parser 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 
    ); 
}