student .xml(course)


<?php //Definestudentdetails $students=array( Array(“rollno”=>1,“name”=>“JohnDoe”,“address”=>“123MainSt”,“college”=>“ABC College”,“course”=>“ComputerScience”), Array(“rollno”=>2,“name”=>“JaneSmith”,“address”=>“456MainSt”,“college”=>“DEF College”,“course”=>“InformationTechnology”), Array(“rollno”=>3,“name”=>“BobJohnson”,“address”=>“789MainSt”,“college”=>“GHI College”,“course”=>“BusinessAdministration”), Array(“rollno”=>4,“name”=>“SarahLee”,“address”=>“101MainSt”,“college”=>“JKL College”,“course”=>“Marketing”), Array(“rollno”=>5,“name”=>“TomBrown”,“address”=>“121MainSt”,“college”=>“MNO College”,“course”=>“ComputerScience”) ); //CreateaSimpleXMLElementobject $xml=newSimpleXMLElement(‘<students></students>’); //AddstudentelementstotheXMLobject Foreach($studentsas$student){ $student_element=$xml->addChild(‘student’); $student_element->addChild(‘rollno’,$student[‘rollno’]); $student_element->addChild(‘name’,$student[‘name’]); $student_element->addChild(‘address’,$student[‘address’]); $student_element->addChild(‘college’,$student[‘college’]); $student_element->addChild(‘course’,$student[‘course’]); } //SavetheXMLdatatoafile $xml->asXML(‘student.xml’); //Getcourseinputfromuser $course=isset($_POST[‘course’])?$_POST[‘course’]:‘’; //LoadtheXMLfile $xml=simplexml_load_file(‘student.xml’); //Findstudentswithmatchingcourse $filtered_students=$xml->xpath(“//student[course=’$course’]”); //Printtableofmatchingstudents Echo“<tableborder=’1’>”; Echo“<tr><th>Roll No</th><th>Name</th><th>Address</th><th>College</th><th>Course</th></tr>”; Foreach($filtered_studentsas$student){ Echo“<tr>”; Echo“<td>{$student->rollno}</td>”; Echo“<td>{$student->name}</td>”; Echo“<td>{$student->address}</td>”; Echo“<td>{$student->college}</td>”; Echo“<td>{$student->course}</td>”; Echo“</tr>”; } Echo“</table>”; ?