我有以下字符串,我想从这个字符串中解析用户名和密码......
$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 :(得分:0)
也许您可以使用PHP5 Soap Client,而不是simple_xml_parser 正如How to parse SOAP XML?
所建议的那样答案 1 :(得分: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
);
}
答案 2 :(得分:0)
尝试使用以下asXML函数将为您提供来自
的xml格式字符串的print_r(ヶ辆($ xmldata-&GT; asXML()));
有关更多信息,请查看以下链接
Simplexml_load_string($string) returns an empty object but $string contains xml? code below