lastChild; // no 'getDocumentElement' in PHP $k = 0; //number of students/marks $s = 0; //total $studs = $start->getElementsByTagName("student"); foreach( $studs as $stud ){ // foreach works with a NodeList ! $the_name = $stud->getAttribute("name"); $the_mark = $stud->getAttribute("mark"); echo "$the_name 's mark is $the_mark\n"; $s += $the_mark; $k++; } if( $k == 0 ){ die("empty data"); }else{ return $s/$k; } }// average_1 function reading ($fichIn){ $doc = new DOMDocument(); $doc->load($fichIn); $moy = average_1($doc); echo "\nAverage : $moy\n"; }//reading reading($argv[1]); ?>