我如何打印(回显)“ supplierName”属性?
我有可为我带来数据的网络服务
global $s;
global $params;
$s = new soapclient($conDetails['url'],array('wsdl'));
$params = new stdClass;
$paramsStr = '
<LoginInput>
<LoginRec Action="SuppAuthn" UserEmail="'.$email.'" UserPass="'.$password.'" />
</LoginInput>
';
$params->xmlRequest = $paramsStr;
$result = $s->__call("SubmitXmlString",array($params));
打印的数据如下:
echo "<pre>".(var_dump($result,true))."</pre>";
object(stdClass)#3 (1) {
["SubmitXmlStringResult"]=> string(496)
"<LoginOutput>
<Login UsrId="30" UsrName="Some Name" SessionId="10" supplierCode="2" supplierName="Supp name" supplierEmail=""/>
<Countries>
<country code="DE" name="Germany"/>
<country code="ES" name="Spain"/>
<country code="FR" name="France"/>
</Countries>
</LoginOutput>
" } bool(true)
我如何打印(回显)“ supplierName”属性?
我尝试过:
$xmlString = $result->SubmitXmlStringResult;
$xml = simplexml_load_string($xmlString);
echo $xml->LoginOutput->Login[0]->attributes()->supplierName;
echo $xml->Login['supplierName'];
但是它不起作用
答案 0 :(得分:0)
以[]
表示法访问属性:
$xml = simplexml_load_string($xmlString);
echo $xml->Login['supplierCode']; // no need for [0] if `Login` is a single node