the code section is displayed below
$xml = simplexml_load_file($_POST['feedurl']);
foreach($xml->TT as $TT)
{
foreach($TT->TOTS as $TOTS)
{
$cnt++;
foreach($TT->TOTS[$cnt]->attributes() as $a => $b) // problematic
line.
{
// DISPLAY THE TITLE AND THE VALUES
//echo " $a $b <br/>";
}
}
}
the error occours when the parser reaches the end of the last element and
then fires the error
Fatal error: Call to a member function attributes() on a non-object in line
(see problematic line)
How can i solve that or determine when there are no more tags to parse.
JM Guillermin <[EMAIL PROTECTED]> wrote:
And with :
foreach ($xml as $cs) {
.....
}
??
jm
----- Original Message -----
From: "Don Don"
To: "PHP List"
Sent: Thursday, April 05, 2007 10:32 AM
Subject: [PHP] SimpleXML end of element/tag error
>I am using simple xml to parse an xml file, the program parses the file and
>produces an error at the end of the foreach loop when it reaches the end of
>the tag, it tries to look for an element/tag when there is none and
>produces an error "Call to a member function attributes() on a non-object"
>the foreach loop looks like this
>
> foreach($xml->CS as $CS)
> {
> //processing takes place here
> }
>
> when there are no more CS it fires an error
>
> How can i detect when there are no more elements/tags to parse and handle
> it?
>
>
> cheers
>
>
> ---------------------------------
> It's here! Your new message!
> Get new email alerts with the free Yahoo! Toolbar.
---------------------------------
Now that's room service! Choose from over 150,000 hotels
in 45,000 destinations on Yahoo! Travel to find your fit.