2012-07-20 68 views
0

可能重复:
Able to see a variable in print_r()'s output, but not sure how to access it in code解析XML阵列PHP

SimpleXMLElement Object 

(
[Header] => SimpleXMLElement Object 
    (
    ) 

[Body] => SimpleXMLElement Object 
    (
     [CreateUserResponse] => SimpleXMLElement Object 
      (
       [username] => anup_165 
       [password] => xnrrtgohgv 
       [result] => SimpleXMLElement Object 
        (
         [succeeded] => true 
         [errorCode] => 0 
         [errorText] => SimpleXMLElement Object 
          (
          ) 

        ) 

      ) 

    ) 

) 

我想获取用户名,密码,并从上述阵列

回答

1

成功你的意思是:

$username = (string) $xml->Body["CreateUserResponse"]->username; 
$password = (string) $xml->Body["CreateUserResponse"]->password; 
1

好吧,我的肢体会在这里,但它可能是这样的:

$object['body']['CreateUserResponse']['username'] 


$对象[ '身体'] [ 'CreateUserResponse'] [ '密码']

0
//For Parsing the xml 
    $xmltoaparse=simplexml_load_string($xmlresponse); 


    foreach($xmltoaparse->children() as $iasorecord) 
    { 

      foreach($iasorecord as $iasouserrecord) //for each for machhnia attributes 
        { 
         foreach($iasouserrecord as $iasousersrecord) //for each for machhnia attributes 
          { 

       echo $iasousersrecord->getName(); 
       echo $iasousersrecord; 


          } 
        } 
    }