1

Im having some trouble looping through some xml data.

The xml file is structured like this:

<users type="array">
 −&lt;user>
   <id>14527576</id>
  </user>
 −&lt;user>
   <id>14527576</id>
  </user>
 −&lt;user>
   <id>14527576</id>
  </user>

My php to loop through it looks like this

$xml = simplexml_load_string($rawxml);
foreach($xml->users AS $key){
    $id = $key->user->{"id"};

But its not throwing errors, or returning anything

4

1 回答 1

2

Users is your root element. You need just to enumerate it.

$xml = simplexml_load_string( $rawxml );

foreach($xml as $user){
  print $user->id . '<br />';
}
于 2009-11-05T15:14:54.943 回答