simplexml object node iteration
Posted
by
MorbidWrath
on Stack Overflow
See other posts from Stack Overflow
or by MorbidWrath
Published on 2013-10-19T21:42:19Z
Indexed on
2013/10/19
21:54 UTC
Read the original article
Hit count: 182
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?
© Stack Overflow or respective owner