Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
20 views5 pages

SET A: Teacher - XML - Store & Display Teacher Data

The document outlines the creation and display of XML data related to teachers, players, and subjects using PHP. It includes examples of XML files for teacher data, player statistics, and subject codes, along with corresponding PHP scripts to read and display this data. The document serves as a guide for generating and manipulating XML in a web development context.

Uploaded by

Ashwini Khade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views5 pages

SET A: Teacher - XML - Store & Display Teacher Data

The document outlines the creation and display of XML data related to teachers, players, and subjects using PHP. It includes examples of XML files for teacher data, player statistics, and subject codes, along with corresponding PHP scripts to read and display this data. The document serves as a guide for generating and manipulating XML in a web development context.

Uploaded by

Ashwini Khade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

✅ SET A: Teacher.

xml – Store & Display Teacher Data

1️⃣ Create XML file: Teacher.xml

xml
CopyEdit
<?xml version="1.0" encoding="UTF-8"?>
<Department>
<ComputerScience>
<Teacher>
<Name>Dr. Aruna Joshi</Name>
<Qualification>NET</Qualification>
<SubjectTaught>Data Structures</SubjectTaught>
<Experience>10</Experience>
</Teacher>
<Teacher>
<Name>Mr. Kunal Patil</Name>
<Qualification>NET</Qualification>
<SubjectTaught>Web Development</SubjectTaught>
<Experience>5</Experience>
</Teacher>
<Teacher>
<Name>Ms. Neha Kulkarni</Name>
<Qualification>NET</Qualification>
<SubjectTaught>Database</SubjectTaught>
<Experience>8</Experience>
</Teacher>
<Teacher>
<Name>Dr. Sanjay Mehta</Name>
<Qualification>NET</Qualification>
<SubjectTaught>AI</SubjectTaught>
<Experience>12</Experience>
</Teacher>
<Teacher>
<Name>Mrs. Sheetal Rao</Name>
<Qualification>NET</Qualification>
<SubjectTaught>Computer Networks</SubjectTaught>
<Experience>6</Experience>
</Teacher>
</ComputerScience>
</Department>

2️⃣ Display XML data using PHP (display_teacher.php)

php
CopyEdit
<?php
$xml = simplexml_load_file("Teacher.xml");

echo "<h2>Teacher Details (Qualification: NET)</h2>";


echo "<table border='1' cellpadding='10'>";
echo
"<tr><th>Name</th><th>Qualification</th><th>Subject</th><th>Experience</
th></tr>";

foreach($xml->ComputerScience->Teacher as $teacher) {
echo "<tr>";
echo "<td>{$teacher->Name}</td>";
echo "<td>{$teacher->Qualification}</td>";
echo "<td>{$teacher->SubjectTaught}</td>";
echo "<td>{$teacher->Experience} years</td>";
echo "</tr>";
}
echo "</table>";
?>

✅ SET B: Generate XML from PHP

php
CopyEdit
<?php
$xml = new SimpleXMLElement('<ABCCollege></ABCCollege>');
$dept = $xml->addChild("ComputerApplicationDepartment");
$dept->addChild("Course", "BCA(Science)");
$dept->addChild("StudentStrength", "80");
$dept->addChild("NumberOfTeachers", "12");

Header('Content-type: text/xml');
echo $xml->asXML();
?>

✅ SET C:

1️⃣ Player Data XML & Display Players with >100 Runs

player.xml

xml
CopyEdit
<cricket>
<player>
<name>Rohit Sharma</name>
<runs>120</runs>
<wickets>5</wickets>
</player>
<player>
<name>Virat Kohli</name>
<runs>98</runs>
<wickets>2</wickets>
</player>
<player>
<name>Hardik Pandya</name>
<runs>130</runs>
<wickets>8</wickets>
</player>
<player>
<name>MS Dhoni</name>
<runs>75</runs>
<wickets>0</wickets>
</player>
<player>
<name>KL Rahul</name>
<runs>110</runs>
<wickets>3</wickets>
</player>
</cricket>

player_display.php
php
CopyEdit
<?php
$xml = simplexml_load_file("player.xml");

echo "<h2>Players who scored more than 100 runs</h2>";


echo "<table border='1' cellpadding='10'>";
echo "<tr><th>Name</th><th>Runs</th><th>Wickets</th></tr>";

foreach($xml->player as $p) {
if ((int)$p->runs > 100) {
echo "<tr>";
echo "<td>{$p->name}</td>";
echo "<td>{$p->runs}</td>";
echo "<td>{$p->wickets}</td>";
echo "</tr>";
}
}
echo "</table>";
?>

2️⃣ Display Subject Code for “Web Technology Laboratory”

subjects.xml

xml
CopyEdit
<subjects>
<subject>
<code>BCA 241</code>
<name>Operating Systems</name>
</subject>
<subject>
<code>BCA 245</code>
<name>Web Technology Laboratory</name>
</subject>
<subject>
<code>BCA 250</code>
<name>Data Science</name>
</subject>
</subjects>
subject_display.php

php
CopyEdit
<?php
$xml = simplexml_load_file("subjects.xml");

foreach($xml->subject as $sub) {
if (trim($sub->name) == "Web Technology Laboratory") {
echo "<h3>Subject Code: {$sub->code}</h3>";
}
}
?>

You might also like