Jump to content

[SOLVED] simplexml while loop == Call to member function attribues() on a non-object


Serenitee

Recommended Posts

I found simplexml and have been working with it instead of writing my own parser and all is fine until this area:

 

$count = count($file->characters->character);
$i = "0";
while($i <= $count)
{print $file->characters->character[$i]->attributes()->name;
echo "<br>";
print $file->characters->character[$i]->id;
echo "<br>";
print $file->characters->character[$i]->server;
echo "<br>";
print $file->characters->character[$i]->class;
echo "<br>";}

 

specifically:

print $file->characters->character[$i]->attributes()->name;

Will return this error:

Fatal error: Call to a member function attributes() on a non-object in C:\xampp\htdocs\penguin\xmlparse.php on line 110

 

 

If I change the $i to 0 (or 1, 2.. 77), ie:

print $file->characters->character[16]->attributes()->name;

it will return the name from that node (obviously for each instance).  This is only occurring with the attributes areas, but my googlefu is not bringing anything up that explains it.

 

Any thoughts?

tia

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.