tags:

views:

56

answers:

1

Im having some trouble looping through some xml data.

The xml file is structured like this:

<users type="array">
 −<user>
   <id>14527576</id>
  </user>
 −<user>
   <id>14527576</id>
  </user>
 −<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

+2  A: 

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

$xml = simplexml_load_string( $rawxml );

foreach($xml as $user){
  print $user->id . '<br />';
}
silent
its looping through the correct number of time, but its not selectiong the content of each node, its coming back blank
Patrick
Sorry, but I don't understand you. I just give you the right code that I tested and it works with your example :)Each node in my code is visible in foreach loop in $user variable.In your code you just have no variable in $xml->users, you can print_r your $xml variable and see it by yourself.
silent