0

我有一个成功的 soapClient,它从以下 XML 示例生成内容

 <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
 <s:Header>
   <ActivityId xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics" CorrelationId="f62a50bd-af24-4719-acca-fcfb8770028d">ebc35110-673d-4d15-aacd-020e14a8d62b</ActivityId>
 </s:Header>
 <s:Body>
   <GMDataResponse xmlns="http://xx.com/xx">
   <GMDataResult xmlns:a="http://xx.com/xx/GMData" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
   <a:Users>
     <a:MData.UserData>
       <a:ProjectId>37199</a:ProjectId>
       <a:Name>Hilda Smith</a:Name>
       <a:Number>101</a:Number>
       <a:First>Hilda</a:First>
     </a:MData.UserData>
     <a:MData.UserData>
       <a:ProjectId>37199</a:ProjectId>
       <a:Name>John Smith</a:Name>
       <a:Number>102</a:Number>
       <a:First>John</a:First>
     </a:MData.UserData>

我使用以下内容来构建循环并且它可以工作:

 $UsersAr = is_array( $res->GMDataResult->Users )
       ? $res->GMDataResult->Users
       : array( $res->GMDataResult->Users );

 foreach ($UsersAr as $Users) {
     foreach($Users as $UserSet) {
    foreach($UserSet as $u) {
        echo $u->Name ."<br>";
    }
 } 
 }

我尝试:

 foreach ($UsersAr as $users) {
$user = $users->MBData.UserData;
echo $user->Name;
 }

并且它失败了(注意:未定义的属性:stdClass::$MBData) 似乎 MBData.UserData 中的句点正在引发错误?我想要最干净的代码,因为这是一个大容量的过程。

4

1 回答 1

1
$users->{'MBData.UserData'}

$users->MBData.UserData被视为和的$users->MBData串联UserData

参考:http ://www.php.net/manual/en/language.variables.variable.php

于 2013-09-30T02:56:07.737 回答