How to create a XML DTD for displaying student details


XML  is  eXtensible Markup Language which is used to create used defined tags. 
It has
  • Elements  ( <STUDENT>)
  • Attributes (<STUDENT id="21it21">)
To create a XML file, create three files
1 ->  XML file (used to declare the user defined tags)
2 ->  DTD file (used to define the user defined tags)
3 ->  HTML file(used to display the xml file as web page)

create these three files using any editor like notepad. 

Student.Xml
<?xml version="1.0"?>
<!DOCTYPE STUDENTS SYSTEM "E:\XML1\STUDENT.dtd">
<STUDENTS>
 <STUDENT>
 <STUDENTDATA>
    <NAME> SUTHA </NAME>
    <ID>  2007IT51 </ID>
    <AGE> 20 </AGE>
    <ADDRESS> 12,SATHY ROAD,GOBI </ADDRESS>
  </STUDENTDATA>
</STUDENT>
</STUDENTS>

Student.dtd
<?xml version="1.0"?>
<!ELEMENT STUDENTS (STUDENT*)>
<!ELEMENT STUDENT (STUDENTDATA*)>
<!ELEMENT STUDENTDATA (NAME,ID,AGE,ADDRESS)>
<!ELEMENT NAME (#PCDATA)>
<!ELEMENT ID (#PCDATA)>
<!ELEMENT AGE (#PCDATA)>
<!ELEMENT ADDRESS (#PCDATA)>

Student.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"E:\XML1\STUDENT.dtd"">
<html>
<head COLOR:RED><h1 style="color:red">
<MARQUEE DIRECTION="RIGHT"><CENTER> COLLEGE OF ENGINEERING AND TECHNOLOGY </CENTER> </MARQUEE> </H1>
<title> STUDENT DETAILS DISPLAY </title>
</head>
<body style="background-color:PINK"> <H2 STYLE="COLOR: BLUE"> <MARQUEE><CENTER>DEPARTMENT OF INFORMATION TECHNOLOGY </CENTER> </MARQUEE><BR></H2>
<MARQUEE DIRECTION="DOWN"><H3 STYLE= "COLOR:GREEN"><CENTER>FINAL IT STUDENTS DETAILS  </CENTER></MARQUEE><BR><BR></H3>
<CENTER><TABLE BORDER="1">
<THEAD>
<TR>
<TH> NAME </TH>
<TH> ID  </TH>
<TH> AGE  </TH>
<TH> ADDRESS  </TH>
</TR>
</THEAD>
<TFOOT>
<TR>
<TH COLSPAN="4"> STUDENT CATALOG</TH>
</TFOOT>
<TR>
 <TD>SUTHA </TD>
 <TD>2007IT51</TD>
 <TD>20</TD>
 <TD>12,SATHY ROAD,GOBI</TD>
</TR>
</TABLE></CENTER>
</body>
</html>

Run the html file in any browser like Internet explorer....
output will be like this


4 comments: