我有以下字符串,我想从这个字符串中解析用户名和密码......
$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);
然后它工作正常