You are here: Count of elements in XML « PHP « IT news, forums, messages
Count of elements in XML

Posted by Jay Paulson on 01/20/06 19:36

I was wondering if there is a way to get the number of foo elements in my
XML below? This way I could loop through each element and print out the

$string = "<a>
<foo name=\"one\" game=\"lonely\">1</foo>
<foo name=\"two\" game=\"again\">2</foo>
<foo name=\"three\" game=\"blah\">3</foo>
<foo name=\"four\" game=\"goodness\">4</foo>

$xml = simplexml_load_string($string);
// this doesn't return the correct number of elements but instead returns
the data inbetween <foo></foo>
$cnt = count($xml->foo);
for($i=0; $i<$cnt; $i++) {
foreach($xml->foo[$i]->attributes() as $a => $b) {
echo $a,'="',$b,"\"\n";



[Reply to this message]

Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация