simplexml object node iteration
- by MorbidWrath
I have an xml file that I'm parsing with php's simplexml, but I'm having an issue with an iteration through nodes.
the xml:
<channel>
<item>
<title>Title1</title>
<category>Cat1</category>
</item>
<item>
<title>Title2</title>
<category>Cat1</category>
</item>
<item>
<title>Title3</title>
<category>Cat2</category>
</item>
</channel>
my counting function:
public function cat_count($cat){
$count = 0;
$items = $this->xml->channel->item;
$size = count($size);
for($i=0;$i<$size;$i++){
if($items[$i]->category == $cat){
$count++;
}
}
return $count;
}
Am I overlooking an error in my code, or is there another preferred method for iterating through the nodes? I've also used a foreach and while statement with no luck, so I'm at a loss. Any suggestions?