Write a script to create XML file - PHP | IProgramX

Slip no. 1. Write a script to create XML file ‘University.xml’. The element details of ‘University.xml’
Are as follows:
<Univ>
<Uname>------------</Uname>
<CITY>-----------------</CITY>
<Rank>----------------<</Rank>
</Univ>
a) Store the details of at least 3 universities.
b) Link the ‘University.xml’ file to CSS and get well formatted output as given below.
i) Uname :
                Color : black;
                Font-family: copperplate G0thic Light;
                Font size: 16pt;
                Font:Bold;
ii) City and Rank
                Color: Yellow;
Font-family: Arial;
                Font-size : 12pt;
                Font: Bold;


XML file : university.xml

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="university.css"?>
<Uni>
                <U_info>
                                <Uname>Pune University</Uname>
                                <City>Pune</City>
                                <Rank>First</Rank>
                </U_info>
                <U_info>
                                <Uname>Mumbai University</Uname>
                                <City>Mumbai</City>
                                <Rank>Third</Rank>
                </U_info>
                <U_info>
                                <Uname>Latur University</Uname>
                                <City>Latur</City>
                                <Rank>Fifth</Rank>
                </U_info>
</Uni>


CSS file : university.css
Uname
{
                color:black;
                font-family: copperplate Gothic Light;
                font-size: 16pt;
                font: bold;
}
City,Rank
{
                color:yellow;
                font-family:arial;
                font-size: 12pt;
                font: bold;
}

PHP file :

<?php
                $xml=simplexml_load_file("university.xml") or die("eror:cannot create object");
                echo "<table border=1 align=center>";
                echo "<tr><td>Univercity Name</td><td>City</td><td>Rank</td></tr>";
                foreach($xml->children() as $uni)
                {
                                echo "<tr><td>".$uni->Uname."</td>";
                                echo "<td>".$uni->City."</td>";
                                echo "<td>".$uni->Rank."</td></tr>";
                }
                echo "<table>";
?>

Post a Comment

0 Comments