Você está na página 1de 41

WEB AND INTERNET TECHNOLOGIES LABORATORY

III B.Tech II - Semester


(15A05609) Web and Internet Technologies LAB

Objectives:
 To introduce client side scripting with Javascript and DHTML
 To introduce server side programming with Java servlets, JSP and PHP.
 To learn the basic web concepts and Internet protocols

List of Experiments/Tasks

1. To create a simple student bio-data form using html5 . it should contain the following
name (text box), address (multiline text box),gender (radio button male, female),skill sets
known (check boxes – , c++, java, C# etc), extra- curricular
activities (text box), nationality (combo box) ,submit and reset button.
2. To create an html page with different types of frames such as floating frame, navigation
frame & mixed frame.
3. Design the webpage by applying the different styles using inline, external & internal style
sheets.
4. Write a java script program to read .XML file and display data in a neat format.
5. To write a Javascript program to define a user defined function for sorting the values in an
array. Use HTML5 for user interface.
6. To create an html page to demonstrate exception handling in javascript Create an html page
named as ―exception.html‖ and do the following.
i. within the script tag write code to handle exception
a) define a method RunTest() to get any string values(str) from the user and call the
method Areletters(str).
b) In Areletters(str) method check whether str contain only alphabets (a-z, A- Z), if not
throw exception.
c) Define a exception method Input Exception(str) to handle the exception thrown by the
above method.
ii. Within the body tag define a script tag to call Runtest() method define.

7. Write a jsp servlet program to implement the single text field calculator.
8. Write a jsp servlet program to demonstrate session handling using
– url rewriting
--hidden formfield
--cookies
--sessions
9. To create a php program to demonstrate the different predefined function in array, Math,
Data & Regular Expression.
Procedure:
 Create php file named as Regularexpression.php
 for demonstrating the method for handling various strings with regular
expression Array.php

Siddartha Institute of Science and Technology Page 1


WEB AND INTERNET TECHNOLOGIES LABORATORY

 for demonstrating the methods for handling the array values


Math_function.php
 to demonstrate the predefined in math objects. Date_time.php to demonstrate the
predefined function in date Subject.
10. Write a program in PHP for a simple email processing with attachment using forms
11. Write a program for PHP for a login script ; create a login database and store username and
password
12. Write a program in PHP to add, update and delete using student database
13. Create a DTD to describe a library. Library has one or more books, members and staffs.
• Each book has BookID(Attribute), Title, one or more Authors, Publisher Year of
Publication, ISBN and Price.
• Each Member has MemeberID(Attribute), Name, Address, Phone number.
• Each Staff has StaffID(Attribute), Name, Address, Phone number.
• Each Author has AuthorID(Attribute), Name, Address, Phone number.
• Each Publisher has PublisherID(Attribute), Name, Address, Phone number.
• Use it in a XML document.

14. Create a DTD to describe a Computer. A computer has following details,


• Type of computer (this is an attribute), Which can be Desktop PC, Laptop, Palm Top,
Server, Minicomputer or mainframe)
• A Monitor with Serial Number (Attribute), Make, Model, Year of manufacture, Size, Type
(which is either colour or Monochrome)
• A keyboard with Serial Number (Attribute), Make, Model, Year of manufacture, No of keys,
Type( which is either Standard or Enhanced or Multimedia)
• A mouse with Serial Number (Attribute), Make, Model, Year of manufacture, No of buttons,
Scroll wheel (which is yes or no), Type (Which is Ball or Optical)
 A Mother board with Serial Number (Attribute), Make, Model, Year of manufacture, No
of USB ports, No of IDE slots, No of SATA hubs, No of PCI slots, Display Type(Which is
VGA or HDMI), Number of Processor slots, Type of Processors supported (must be a list),
Type of RAM supported (Which is either SD or DDR1 or DDR2 or RD), Maximum Capacity
of RAM, Form Factor (which is either AT or Baby AT), On Board sound card (Which is yes or
no)
• A Microprocessor with Serial Number (Attribute), Make, Model, Year of
manufacture, speed (in GHz), No of Cores (Single, Dual, Quad)
• A power supply with Serial Number (Attribute), Make, Model, Year of manufacture,
Type (AT, ATX), Wattage
• One or more hard disks, each Hard disk must have Serial Number (Attribute), Make, Model,
Year of manufacture, capacity and type (Which is IDE or SATAI or SATAII, SCSI)
• One or more RAM SIMM, with Serial Number (Attribute), Make, Model, Year of manufacture,
Type (which must be SD, DDRI, DDRII, RD), capacity, operating frequency. Use it in a XML
document.
15. Create a Schema to describe a Computer. Use the previous question‘s details and show an instance
Siddartha Institute of Science and Technology Page 2
WEB AND INTERNET TECHNOLOGIES LABORATORY

XML document.
16. Create a Schema to describe a library. Library has one or more - books, members and staffs.
• Each book has BookID(Attribute), Title, one or more Authors, Publisher Year of Publication,
ISBN and Price.
• Each Member has MemeberID(Attribute), Name, Address, Phone number.
• Each Staff has StaffID(Attribute), Name, Address, Phone number.
• Each Author has AuthorID(Attribute), Name, Address, Phone number.
• Each Publisher has PublisherID(Attribute), Name, Address, Phone number. Use the above
DTD in a sample XML document.
17. Create a DTD to describe a bank that has one or more customers, accounts or Employee.
• Each Customer has a Customer ID, Name and address.
• Each account has an account ID, BranchID, CustomerID, Account Type and Balance.
• Each Employee has aEmpID, Name, Designation, DOJ, Salary and Address. Use this DTD
in a XML file.
18. Create Schema describe a bank that has one or more customers, accounts or depositors. Use
the previous questions details. Also show a sample instance XML document.

Outcomes:
 Ability to create dynamic and interactive web sites.
 Gain knowledge of client side scripting using java sript and DHTML.
 Demonstrate understanding of what is XML and how to parse and use XML data
 Able to do server side programming with Java Servelets, JSP and PHP

1. To create a simple student bio-data form using html5 . it should contain the following
name (text box), address (multiline text box),gender (radio button male,female),skill sets
known (check boxes – c,c++,java,C#etc), extra curricular activities (text box), nationality
(combobox) ,submit and reset button.
<html>
<head>
<script type="text/javascript" src="validate.js"></script>
</head>
<body>
<form action="#" name="StudentRegistration" onsubmit="return(validate());">

<table cellpadding="2" width="20%" bgcolor="99FFFF" align="center"


cellspacing="2">

<tr>
<td colspan=2>
<center><font size=4><b>Student Bio-Data Form</b></font></center>
</td>
</tr>

<tr>
<td>Name</td>
<td><input type="text" name="textnames" id="textname" size="30"></td>
</tr>

<tr>
<td>Address</td>

Siddartha Institute of Science and Technology Page 3


WEB AND INTERNET TECHNOLOGIES LABORATORY

<td>
<textarea name="address" cols="30" rows="5"></textarea>

</td>
</tr>
<tr>
<td>Sex</td>
<td><input type="radio" name="sex" value="male" size="10">Male
<input type="radio" name="sex" value="Female" size="10">Female</td>
</tr>
<tr>
<tr>
<td><label>skill sets known</label></td></tr>

<tr>
<tr><td><input type="checkbox" name="lang" value="c">C</td>
<td><input type="checkbox" name="lang" value="cpp">C++</td>
</tr>
<tr>
<td><input type="checkbox" name="lang" value="java">Java</td>
<td><input type="checkbox" name="lang" value="csharp">C#</td>
</tr>

<tr>
<td>Extra Curriculam Activities</td>
<td><input type="text" name="pincode" id="pincode" size="30"></td>

</tr>

<tr>
<td>Nationality</td>
<td><select Name="State">
<option value="-1" selected>select..</option>
<option value="New Del34edxhi">Indian</option>
<option value="Mumbai">German</option>
<option value="Goa">Italian </option>

</select></td>
</tr>

<tr>
<td><input type="reset"></td>
<td colspan="2"><input type="submit" value="Submit Form" /></td>
</tr>
</table>
</form>
</body>
</html>

Validate.js
//<script type="text/javascript">
function validate()
{
if( document.StudentRegistration.textnames.value == "" )
{
alert( "Please provide your Name!" );
document.StudentRegistration.textnames.focus() ;
return false;
}

Siddartha Institute of Science and Technology Page 4


WEB AND INTERNET TECHNOLOGIES LABORATORY

var a = document.StudentRegistration.address.value;
if(a=="")
{
alert("please Enter the Address details");
document.form.address.focus();
return false;
}

if ( ( StudentRegistration.sex[0].checked == false ) && ( StudentRegistration.sex[1].checked == false ) )


{
alert ( "Please choose your Gender: Male or Female" );
return false;
}

var group = document.StudentRegistration.lang;


for (var i=0; i<group.length; i++) {
if (group[i].checked)
break;
}
if (i==group.length)
return alert("No Checkbox is checked");
alert("Radio Button " + (i+1) + " is checked.");

return( true );
}
//</script>

Output:

Siddartha Institute of Science and Technology Page 5


WEB AND INTERNET TECHNOLOGIES LABORATORY

2. To create an html page with different types of frames such as floating frame, navigation frame &
mixed frame

Mainpage.html

<html>
<body>
<a href="frames.html" target="two">navigation frame</a><br>
<a href="floatingframe.html" target="two">floating frame</a><br>
<a href="Noframe.html" target="two">no frame</a><br>
<a href="mixedframe.html" target="two">mixed frame</a><br>
</body>
</html>

Frame.html

<html>
<frameset cols="20%,35%,*" scrolling="no" noresize>
<frame name="one" src="MainPage.html"></frame>
<frame src="aa.gif"></frame>
<frame name="two" src="hulk.gif"></frame>
</frameset>
</html>

Floatingframe.html

<html>
<body>
<p> Explanation: There is a problem with the page you are trying to reach and it
cannot be displayed.

Siddartha Institute of Science and Technology Page 6


WEB AND INTERNET TECHNOLOGIES LABORATORY

Try the following: * Refresh page: Search for the page again by clicking the Refresh
button. The timeout may have occurred due to Internet congestion.
* Check spelling: Check that you typed the Web page address correctly. The
address may have been mistyped.
* Access from a link: If there is a link to the page you are looking for, try accessing
the page from that link.
If you are still not able to view the requested page, try contacting you
<iframe src="bb.gif" height="225" width="500">
</iframe>
<iframe src="MainPage.html" height="50%" width="50%">
</iframe>
</body>
</html>

Mixedframe.html

<html>
<frameset cols="30%,*">
<frame src="pic.html"></frame>
<frameset rows="50%,*">
<frame src="video.html" autostart="true">
<frame src="Q3.html" >
</frameset>
</frameset>
</html>

navigationframe.html

<html>
<frameset cols="25%,*" scrolling="no" noresize>
<frame name="one" src="MainPage.html">
</frame>
<frame name="two" ></frame>
<frameset rows="30%,*">
<frame src="hulk.gif">
</frame>
</frameset>
</html>

Output:

Siddartha Institute of Science and Technology Page 7


WEB AND INTERNET TECHNOLOGIES LABORATORY

3. Design the webpage by applying the different styles using inline, external & internal style sheets.
Inline:
<html>
<head> Inline Web Page </head>
<body>
<h1 style="color:blue;">This is a Blue Heading</h1>
</body>
</html>

Internal:

<!DOCTYPE html>
<html>
<head>
<style>
body {background-color: powderblue;}
h1 {color: blue;}
p {color: red;}
</style>
</head>
<body>

<h1>This is a heading</h1>
<p>This is a paragraph.</p>

</body>
</html>

External:-

<!DOCTYPE html>

Siddartha Institute of Science and Technology Page 8


WEB AND INTERNET TECHNOLOGIES LABORATORY

<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>

<h1>This is a heading</h1>
<p>This is a paragraph.</p>

</body>
</html>

Output:

4. Write a java script program to read .XML file and display data in a neat format.

Xml.xml

<?xml version="1.0"?>

<company>
<employee>
<name>King</name>
<age>30</age>
<salary>30000</salary>
</employee>
</company>

</xml>

Xml.html
<html>

<head>
<title>Reading HTML File</title>

<script type="text/javascript">
function readXML()
{
var xml=new XMLHttpRequest();
xml.open('GET','xml.xml',false);
xml.send();

Siddartha Institute of Science and Technology Page 9


WEB AND INTERNET TECHNOLOGIES LABORATORY

var xmlData=xml.responseXML;
if(!xmlData)
{
xmlData=(new DOMParser()).parseFromString

(xml.responseText,'text/xml');
var emp=xmlData.getElementsByTagName("employee");
var name=emp[0].getElementsByTagName("name")

[0].firstChild.data;
var name=emp[0].getElementsByTagName("age")

[0].firstChild.data;
var name=emp[0].getElementsByTagName("salary")

[0].firstChild.data;

document.write("Name="+name+"<br>");
document.write("Age="+age+"<br>");
document.write("Salary="+salary+"<br>");
}
}
</script>
</head>
<body>
<h1>XML File</h1>
<button onclick="readXML()">Read XML File</button>
</body>
</html>

Output:

5. To write a Javascript program to define a user defined function for sorting the values in an array.
Use HTML5 for user interface.

<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Array Sort</h2>
<p>Click the button to sort the array in ascending order.</p>
<button onclick="myFunction()">Try it</button>

Siddartha Institute of Science and Technology Page 10


WEB AND INTERNET TECHNOLOGIES LABORATORY

<p id="demo"></p>
<script>
var points = [40, 100, 1, 5, 25, 10];
document.getElementById("demo").innerHTML = points;
function myFunction() {
points.sort(function(a, b){return a - b});
document.getElementById("demo").innerHTML = points;
}
</script>
</body>
</html>
Output:

6. To create an html page to demonstrate exception handling in javascript


Create an html page named as “exception.html” and do the following.
i. within the script tag write code to handle exception
a) define a method RunTest() to get any string values(str) from the user and call
the method Areletters(str).
b) In Areletters(str) method check whether str contain only alphabets (a-z, A-
Z), if not throw exception.
c) Define a exception method Input Exception(str) to handle the exception
thrown by the above method.
ii. Within the body tag define a script tag to call Runtest() method define.

<html>
<head>
<script type="text/javascript" language="javascript">
function InputException(msg)
{
this.val = msg;
this.toString = function()
{
return "Input Exception in = "+this.val;
}
}
function AreLetters(msg)
{
var input = msg;
var re = new RegExp("[^a-zA-Z]");
if(input.match(re))
{
oops = new InputException(input);
throw oops;

Siddartha Institute of Science and Technology Page 11


WEB AND INTERNET TECHNOLOGIES LABORATORY

}
else
{
document.write("<br>"+input);
}
}
function RunTest()
{
var input = prompt("type something","");
try
{
AreLetters(input);
}
catch(e)
{
document.write("<br>exception occured and caught"+e.toString());
}
document.write("<h1>Exception Handling</h1>");
}
</script>
</head>
<body>
<script language="javascript" type="text/javascript">
RunTest();
</script>
</body>
</html>

Output:

7. Write a jsp servlet program to implement the single text field calculator.

Calculator.html
<html>
<title>calculator</title>

Siddartha Institute of Science and Technology Page 12


WEB AND INTERNET TECHNOLOGIES LABORATORY

<head><h1><center>Basic Calculator</center></h1></head>
<body>
<center>
<form action="calculator.jsp" method="get">

<label for="num1"><b>Number 1</b></label>


<input type="text" name ="num1"><br><br>
<label for = "num2"><b>Number 2</b></label>
<input type="text" name="num2"><br><br>

<input type ="radio" name = "r1" value="Add">+


<input type = "radio" name = "r1" value="Sub">-<br>
<input type="radio" name="r1" value ="mul">*
<input type = "radio" name="r1" value="div">/<br><br>

<input type="submit" value="submit">


</center>

</body>
</html>
Calculator.jsp
<html>
<title>calculator</title>
<head></head>
<body>
<%@page language="java"%>
<%
int num1 = Integer.parseInt(request.getParameter("num1"));
int num2 = Integer.parseInt(request.getParameter("num2"));

String operation = request.getParameter("r1");

if(operation.equals("Add")){
int add=num1+num2;
out.println("Addition is: "+add);
}
else if(operation.equals("Sub")){

int sub=num1-num2;
out.println("Substraction is: "+sub);
}
else if(operation.equals("mul")){
int mul=num1*num2;
out.println("multiplication is: "+mul);
}
else if(operation.equals("div"))
{ int div = num1/num2;
if(num1>=num2)
out.println("division is: "+div);
else
out.println("The division cannot be performed");
}
%>
</body>
</html>

Output:

Siddartha Institute of Science and Technology Page 13


WEB AND INTERNET TECHNOLOGIES LABORATORY

8. Write a jsp servlet program to demonstrate session handling using


– url rewriting
--hidden formfield
--cookies
--sessions

Index.html

<form action="servlet1">
Name:<input type="text" name="userName"/><br/>
<input type="submit" value="go"/>
</form>

FirstServlet.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class FirstServlet extends HttpServlet {


public void doGet(HttpServletRequest request, HttpServletResponse response){
try{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String n=request.getParameter("userName");
out.print("Welcome "+n);

Cookie ck=new Cokkie(“uname”,n); //creating cookie object


Response.addCookie(ck); //adding cookie in the response
HttpSession session=request.getSession();

Siddartha Institute of Science and Technology Page 14


WEB AND INTERNET TECHNOLOGIES LABORATORY

session.setAttribute("name",n);

//creating form that have invisible textfield


out.print("<form action='servlet2'>");
out.print("<input type='hidden' name='uname' value='"+n+"'>");
out.print("<input type='submit' value='go'>");
out.print("</form>");
out.close();

}catch(Exception e){System.out.println(e);}
}

SecondServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SecondServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
try{
response.setContentType("text/html");
PrintWriter out = response.getWriter();

Cookie ck[]=request.getCookies();
out.print(“Hello”+ck[0].getValue());

HttpSession session=request.getSession(false);
String n=(String)session.getAttribute(“uname”);
out.print(“Session”+n);

//Getting the value from the hidden field


String n=request.getParameter("uname");
out.print("Hello "+n);

out.close();
}catch(Exception e){System.out.println(e);}
}
}
web.xml
<web-app>

<servlet>
<servlet-name>s1</servlet-name>
<servlet-class>FirstServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>s1</servlet-name>
<url-pattern>/servlet1</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>s2</servlet-name>
<servlet-class>SecondServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>s2</servlet-name>
<url-pattern>/servlet2</url-pattern>

Siddartha Institute of Science and Technology Page 15


WEB AND INTERNET TECHNOLOGIES LABORATORY

</servlet-mapping>

</web-app>

Output:

9. To create a php program to demonstrate the different predefined function in array, Math, Data &
Regular Expression.

<!DOCTYPE html>
<html>
<body>

<?php

//math functions
echo(abs(6.7) . "<br>");
echo(floor(0.60) . "<br>");
echo(pow(2,4) . "<br>");
echo(round(0.60) . "<br>");

//add date
$date=date_create("2013-03-15");
date_add($date,date_interval_create_from_date_string("40 days"));
echo date_format($date,"Y-m-d");

//array values
$cars=array("Volvo","BMW","Toyota");
echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";

$regex = "/[a-zA-Z]+ \d+/";


if (preg_match($regex, "June 24"))
{
// Indeed, the expression "[a-zA-Z]+ \d+" matches the date string
echo "Found a match!";
}
else
{

Siddartha Institute of Science and Technology Page 16


WEB AND INTERNET TECHNOLOGIES LABORATORY

// If preg_match() returns false, then the regex does not


// match the string
echo "The regex pattern does not match. :(";
}

?>

</body>
</html>

Output:

10. Write a program in PHP for a simple email processing with attachment using forms

<?php
function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject,
$message) {
$file = $path.$filename;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$header = "From: ".$from_name." <".$from_mail.">\r\n";
$header .= "Reply-To: ".$replyto."\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
+ng(1)+"password is"+rs.getString(2)+"</h1>"); }

Siddartha Institute of Science and Technology Page 17


WEB AND INTERNET TECHNOLOGIES LABORATORY

con.close();

else if(ch==2)

Class.forName("oracle.jdbc.driver.OracleDriver");

Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","hrushi");

String sql="insert into person values("+s1+","+s2+")";

PreparedStatement pt=con.prepareStatement(sql);

int i=pt.executeUpdate();

out.println("<h1>insertion succeeded");

Statement st=con.createStatement();

ResultSet rs=st.executeQuery("select * from person");

while(rs.next())

out.println("<h1> user name is"+rs.getString(1)+"password is"+rs.getString(2)+"</h1>");

con.close(); }

else if(ch==3)

Class.forName("oracle.jdbc.driver.OracleDriver");

Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","hrushi");

String sql="delete * from person where pname="+s1;

PreparedStatement pt=con.prepareStatement(sql);

int i=pt.executeUpdate();

if(i!=-1)

out.println("<h1>deletion succeeded");

Statement st=con.createStatement();

ResultSet rs=st.executeQuery("select * from person");

while(rs.next())

{ out.println("<h1> user name is"+rs.getString(1)+"password is"+rs.getString(2)+"</h1>");


}

Siddartha Institute of Science and Technology Page 18


WEB AND INTERNET TECHNOLOGIES LABORATORY

con.close();

Else {

Class.forName("oracle.jdbc.driver.OracleDriver");

Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","hrushi");

Statement st=con.createStatement();

ResultSet rs=st.executeQuery("select * from person");

while(rs.next())

if(s1.equals(rs.getString(1)) && s2.equals(rs.getString(2)))

f=1;

else

f=0;

if(f==1)

out.println("<h1>entered user is a valid user and is in database</h1>");

else

out.println("<h1>entered user is a not valid user and is in not database</h1>");

con.close(); } }

catch(Exception e) { e.printStackTrace(); }

} } }

Web.xml:

<?xml version="1.0" encoding="ISO-8859-1" ?>

<web-app >

<servlet>

<servlet-name>week13pgm</servlet-name>

<servlet-class>week13pgm</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>week13pgm</servlet-name>

<url-pattern>/thetwo</url-pattern>

</servlet-mapping>

Siddartha Institute of Science and Technology Page 19


WEB AND INTERNET TECHNOLOGIES LABORATORY

</web-app>

Result:

13. Create a DTD to describe a library. Library has one or more books, members and staffs.
 Each book has BookID(Attribute), Title, one or more Authors, Publisher, Year of Publication, ISBN
and Price.
 Each Member has MemeberID(Attribute), Name, Address, Phone number.
 Each Staff has StaffID(Attribute), Name, Address, Phone number.
 Each Author has AuthorID(Attribute), Name, Address, Phone number.
 Each Publisher has PublisherID(Attribute), Name, Address, Phone number.
 Use it in a XML document.
Code:

Siddartha Institute of Science and Technology Page 20


WEB AND INTERNET TECHNOLOGIES LABORATORY

lib.xml: It contains five elements named book, member, staff, author and publisher.

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE Library SYSTEM "lib.dtd">

<Library>

<Book>

<b_id>1001</b_id>

<b_author>Bill Gates</b_author>

<b_title lang="en">Microsoft word</b_title>

<b_publisher>Tata</b_publisher>

<b_year>2000</b_year>

<b_isbn>2234</b_isbn>

<b_price>800</b_price>

</Book>

<Member>

<m_id>1</m_id>

<m_name>Rajesh</m_name>

<m_address>Khadi Colony</m_address>

<m_phone>9900990099</m_phone>

</Member>

<Staff>

<s_id>2</s_id>

<s_name>Rakul</s_name>

<s_address>Puttur</s_address>

<s_phone>8899009900</s_phone>

</Staff>

<Author>

<a_id>3</a_id>

<a_name>Bill Gates</a_name>

<a_address>USA</a_address>

<a_phone>4177990099</a_phone>

</Author>

<Publisher>

Siddartha Institute of Science and Technology Page 21


WEB AND INTERNET TECHNOLOGIES LABORATORY

<p_id>4</p_id>

<p_name>Tata</p_name>

<p_address>Delhi</p_address>

<p_phone>9966996699</p_phone>

</Publisher>

<Book>

<b_id>1002</b_id>

<b_author>Herbert Schildt</b_author>

<b_title lang="en">Java Complete</b_title>

<b_publisher>Tata</b_publisher>

<b_year>2004</b_year>

<b_isbn>24</b_isbn>89

<b_price>600</b_price>

</Book>

<Member>

<m_id>5</m_id>

<m_name>Kanna</m_name>

<m_address>Tirupathi</m_address>

<m_phone>9966778999</m_phone>

</Member>

<Staff>

<s_id>6</s_id>

<s_name>Robert</s_name>

<s_address>Nagari</s_address>

<s_phone>8899008877</s_phone>

</Staff>

<Author>

<a_id>6</a_id>

<a_name>Herbert Schildt</a_name>

<a_address>London</a_address>

<a_phone>4177996677</a_phone>

</Author>

Siddartha Institute of Science and Technology Page 22


WEB AND INTERNET TECHNOLOGIES LABORATORY

<Publisher>

<p_id>8</p_id>

<p_name>Tata</p_name>

<p_address>Delhi</p_address>

<p_phone>9966996699</p_phone>

</Publisher>

</Library>

2) lib.dtd: Verifying the above lib.xml file for well-formed ness.

<!ELEMENT Library (Book+,Member+,Staff+,Author+,Publisher+)>

<!ELEMENT Book (b_id,b_author,b_title,b_publisher,b_year,b_isbn,b_price)>

<!ELEMENT b_id(#PCDATA)>

<!ELEMENT b_author (#PCDATA)>

<!ELEMENT b_title (#PCDATA)>

<!ELEMENT b_publisher (#PCDATA)>

<!ELEMENT b_isbn (#PCDATA)>

<!ELEMENT b_price (#PCDATA)>

<!ELEMENT Member (m_id,m_name,m_address,m_phone)>

<!ELEMENT m_id(#PCDATA)>

<!ELEMENT m_name (#PCDATA)>

<!ELEMENT m_address (#PCDATA)>

<!ELEMENT m_phone (#PCDATA)>

<!ELEMENT Staff (s_id,s_name,s_address,s_phone)>

<!ELEMENT s_id(#PCDATA)>

<!ELEMENT s_name (#PCDATA)>

<!ELEMENT s_address (#PCDATA)>

<!ELEMENT s_phone (#PCDATA)>

<!ELEMENT Author(a_id,a_name,a_address,a_phone)>

<!ELEMENT a_id(#PCDATA)>

<!ELEMENT a_name (#PCDATA)>

<!ELEMENT a_address (#PCDATA)>

<!ELEMENT a_phone (#PCDATA)>

<!ELEMENT Publisher(p_id,p_name,p_address,p_phone)>

Siddartha Institute of Science and Technology Page 23


WEB AND INTERNET TECHNOLOGIES LABORATORY

<!ELEMENT p_id(#PCDATA)>

<!ELEMENT p_name (#PCDATA)>

<!ELEMENT p_address (#PCDATA)>

<!ELEMENT p_phone (#PCDATA)>

Output:

Siddartha Institute of Science and Technology Page 24


WEB AND INTERNET TECHNOLOGIES LABORATORY

14. Create a DTD to describe a Computer. A computer has following details,


 Type of computer (this is an attribute), Which can be Desktop PC, Laptop, Palm Top, Server, Minicomputer or
mainframe)
 A Monitor with Serial Number (Attribute), Make, Model, Year of manufacture, Size, Type (which is either
colour or monochrome)
 A keyboard with Serial Number (Attribute), Make, Model, Year of manufacture, No of keys, Type( which is
either Standard or Enhanced or Multimedia)
 A mouse with Serial Number (Attribute), Make, Model, Year of manufacture, No of buttons, Scroll wheel
(which is yes or no), Type (Which is Ball or Optical)
 A Mother board with Serial Number (Attribute), Make, Model, Year of manufacture, No of USB ports, No of
IDE slots, No of SATA hubs, No of PCI slots, Display Type(Which is VGA or HDMI), Number of Processor slots,
Type of Processors supported (must be a list), Type of RAM supported (Which is either SD or DDR1 or DDR2
or RD), Maximum Capacity of RAM, Form Factor (which is either AT or Baby AT), On Board sound card (Which
is yes or no)
 A Microprocessor with Serial Number (Attribute), Make, Model, Year of manufacture, speed (in GHz), No of
Cores (Single, Dual, Quad)
 A power supply with Serial Number (Attribute), Make, Model, Year of manufacture, Type (AT, ATX), Wattage
 One or more hard disks, each Hard disk must have Serial Number (Attribute), Make, Model, Year of
manufacture, capacity and type (Which is IDE or SATAI or SATAII, SCSI)
 One or more RAM SIMM, with Serial Number (Attribute), Make, Model, Year of manufacture, Type (which
must be SD, DDRI, DDRII, RD), capacity, operating frequency.
Use it in a XML document.
Code:

Comp.xml: It contains type, monitor, keyboard, mouse, microprocessor, powersupply, HDD, RAM
elements.

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE Computer SYSTEM "lib.dtd">

<Computer>

<Type>Desktop</Type>

<Monitor>

<m_sno>2341</m_sno>

<m_make>Dell</m_make>

<m_model>LED</m_model>

<m_year>2015</m_year>

<m_size>17</m_size>

<m_type>Color</m_type>

</Monitor>

<Keyboard>

Siddartha Institute of Science and Technology Page 25


WEB AND INTERNET TECHNOLOGIES LABORATORY

<k_sno>7890</k_sno>

<k_make>Samsung</k_make>

<k_model>USB</k_model>

<k_year>2015</k_year>

<k_keynos>128<\k_keynos>

<k_type>Multimedia</k_type>

</<Keyboard>

<Mouse>

<mo_sno>5678</mo_sno>

<mo_make>logitech</mo_make>

<mo_model>USB</mo_model>

<mo_year>2015</mo_year>

<mo_nobuttons>2<\mo_nobuttons>

<mo_scroll>yes</mo_scroll>

<mo_type>ball</mo_type>

</Mouse>

<MicroProcessor>

<mp_sno>1234</mp_sno>

<mp_make>intel</mp_make>

<mp_model>Chip</mp_model>

<mp_year>2015</mp_year>

<mp_speed>2GHZ</mp_speed>

<mp_noofcores>dual</mp_noofcores>

</MicroProcessor>

<Powersupply>

<p_sno>1207</p_sno>

<p_make>intel</p_make>

<p_model>WATTS</p_model>

<p_year>2015</p_year>

<p_type>ATX</p_type>

<p_wattage>300</p_wattage>

</Powersupply>

Siddartha Institute of Science and Technology Page 26


WEB AND INTERNET TECHNOLOGIES LABORATORY

<HDD>

<h_sno>1206</h_sno>

<h_make>intel</h_make>

<h_model>Disk</h_model>

<h_year>2015</h_year>

<h_capacity>500GB</h_capacity>

<h_type>IDE</h_type>

</HDD>

<RAM>

<r_sno>1205</r_sno>

<r_make>intel</r_make>

<r_model>GB</r_model>

<r_year>2015</r_year>

<r_type>DDRI</r_type>

<r_capacity>4GB</r_capacity>

<r_of>5240</r_of>

</RAM>

</Computer>

Comp.dtd: It is used to verify validness of comp.xml file.

<!ELEMENT
Computer(Type+,Monitor+,Keyboard+,Mouse+,MicroProcessor+,Powersupply+,HDD+,RAM+)>

<!ELEMENT Type (#PCDATA)>

<!ELEMENT Monitor (m_sno,m_make,m_model,m_year,m_size,m_type)>

<!ELEMENT m_sno (#PCDATA)>

<!ELEMENT m_make(#PCDATA)>

<!ELEMENT m_model(#PCDATA)>

<!ELEMENT m_year (#PCDATA)>

<!ELEMENT m_size (#PCDATA)>

<!ELEMENT m_type (#PCDATA)>

<!ELEMENT Keyboard (k_sno,k_make,k_model,k_year,k_keynos,k_type)>

<!ELEMENT k_sno (#PCDATA)>

<!ELEMENT k_make (#PCDATA)>

Siddartha Institute of Science and Technology Page 27


WEB AND INTERNET TECHNOLOGIES LABORATORY

<!ELEMENT k_model (#PCDATA)>

<!ELEMENT k_year (#PCDATA)>

<!ELEMENT k_keynos (#PCDATA)>

<!ELEMENT k_type (#PCDATA)>

<!ELEMENT Mouse (mo_sno,mo_make,mo_model,mo_year,mo_nobuttons,mo_scroll,mo_type)>

<!ELEMENT mo_sno (#PCDATA)>

<!ELEMENT mo_make (#PCDATA)>

<!ELEMENT mo_model (#PCDATA)>

<!ELEMENT mo_year (#PCDATA)>

<!ELEMENT mo_nobuttons (#PCDATA)>

<!ELEMENT mo_scroll (#PCDATA)>

<!ELEMENT mo_type (#PCDATA)>

<!ELEMENT MicroProcessor(mp_sno,mp_make,mp_model,mp_year,mp_speed,mp_noofcores)>

<!ELEMENT mp_sno (#PCDATA)>

<!ELEMENT mp_make (#PCDATA)>

<!ELEMENT mp_model (#PCDATA)>

<!ELEMENT mp_year (#PCDATA)>

<!ELEMENT mp_speed (#PCDATA)>

<!ELEMENT mp_noofcores (#PCDATA)>

<!ELEMENT Powersupply(p_sno,p_make,p_model,p_year,p_type,p_wattage)>

<!ELEMENT p_sno(#PCDATA)>

<!ELEMENT p_make (#PCDATA)>

<!ELEMENT p_model(#PCDATA)>

<!ELEMENT p_year (#PCDATA)>

<!ELEMENT p_type(#PCDATA)>

<!ELEMENT p_wattage(#PCDATA)>

<!ELEMENT HDD(h_sno,h_make,h_model,h_year,h_capacity,h_type)>

<!ELEMENT h_sno (#PCDATA)>

Siddartha Institute of Science and Technology Page 28


WEB AND INTERNET TECHNOLOGIES LABORATORY

<!ELEMENT h_make (#PCDATA)>

<!ELEMENT h_model (#PCDATA)>

<!ELEMENT h_year (#PCDATA)>

<!ELEMENT h_capacity(#PCDATA)>

<!ELEMENT h_type (#PCDATA)>

<!ELEMENT RAM(r_sno,r_make,r_model,r_year,r_type,r_capacity,r_of)>

<!ELEMENT (#PCDATA)>

<!ELEMENT r_sno (#PCDATA)>

<!ELEMENT r_make (#PCDATA)>

<!ELEMENT r_model (#PCDATA)>

<!ELEMENT r_type (#PCDATA)>

<!ELEMENT r_capacity (#PCDATA)>

<!ELEMENT r_of (#PCDATA)>

Output:

Siddartha Institute of Science and Technology Page 29


WEB AND INTERNET TECHNOLOGIES LABORATORY

15. Create a Schema to describe a Computer. Use the previous question’s details and show an instance
XML document.
Code:

<?xml version="1.0"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="type" type="xs:string"/>

<xs:element name="Monitor">

<xs:complexType>

<xs:sequence>

<xs:element name="m_sno" type="xs:int"/>

<xs:element name="m_make" type="xs:string"/>

<xs:element name="m_model" type="xs:string"/>

<xs:element name="m_year" type="xs:int"/>

<xs:element name="m_size" type="xs:int"/>

<xs:element name="m_type" type="xs:string"/>

</xs:sequence>

</xs:complexType>

</xs:element>

<xs:element name="Keyboard">

<xs:complexType>

Siddartha Institute of Science and Technology Page 30


WEB AND INTERNET TECHNOLOGIES LABORATORY

<xs:sequence>

<xs:element name="k_sno" type="xs:int"/>

<xs:element name="k_make" type="xs:string"/>

<xs:element name="k_model" type="xs:string"/>

<xs:element name="k_year" type="xs:int"/>

<xs:element name="k_keynos" type="xs:int"/>

<xs:element name="k_type" type="xs:string"/>

</xs:sequence>

</xs:complexType>

</xs:element>

<xs:element name="Mouse">

<xs:complexType>

<xs:sequence>

<xs:element name="mo_sno" type="xs:int"/>

<xs:element name="mo_make type="xs:string"/>

<xs:element name="mo_model" type="xs:string"/>

<xs:element name="mo_year" type="xs:int"/>

<xs:element name="mo_nobuttons" type="xs:int"/>

<xs:element name="mo_scroll" type="xs:bool"/>

<xs:element name="mo_type" type="xs:string"/>

</xs:sequence>

</xs:complexType>

</xs:element>

<xs:element name="Microprocessor">

<xs:complexType>

<xs:sequence>

<xs:element name="mp_sno" type="xs:int"/>

<xs:element name="mp_make" type="xs:string"/>

<xs:element name="mp_model" type="xs:string"/>

<xs:element name="mp_year" type="xs:int"/>

Siddartha Institute of Science and Technology Page 31


WEB AND INTERNET TECHNOLOGIES LABORATORY

<xs:element name="mp_speed" type="xs:int"/>

<xs:element name="mp_noofcores" type="xs:string"/>

</xs:sequence>

</xs:complexType>

</xs:element>

<xs:element name="Powersupply">

<xs:complexType>

<xs:sequence>

<xs:element name="p_sno" type="xs:int"/>

<xs:element name="p_make" type="xs:string"/>

<xs:element name="p_model" type="xs:string"/>

<xs:element name="p_year" type="xs:int"/>

<xs:element name="p_type" type="xs:string"/>

<xs:element name="p_wattage" type="xs:int"/>

</xs:sequence>

</xs:complexType>

</xs:element>

<xs:element name="HDD">

<xs:complexType>

<xs:sequence>

<xs:element name="h_sno" type="xs:int"/>

<xs:element name="h_make" type="xs:string"/>

<xs:element name="h_model" type="xs:string"/>

<xs:element name="h_year" type="xs:int"/>

<xs:element name="h_capacity" type="xs:int"/>

<xs:element name="h_type" type="xs:string"/>

</xs:sequence>

</xs:complexType>

</xs:element>

Siddartha Institute of Science and Technology Page 32


WEB AND INTERNET TECHNOLOGIES LABORATORY

<xs:element name="RAM">

<xs:complexType>

<xs:sequence>

<xs:element name="r_sno" type="xs:int"/>

<xs:element name="r_make" type="xs:string"/>

<xs:element name="r_model" type="xs:string"/>

<xs:element name="r_year" type="xs:int"/>

<xs:element name="r_type" type="xs:int"/>

<xs:element name="r_capacity" type="xs:int"/>

<xs:element name="r_capacity" type="xs:r_of"/>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

Output:

Siddartha Institute of Science and Technology Page 33


WEB AND INTERNET TECHNOLOGIES LABORATORY

16. Create a Schema to describe a library. Library has one or more - books, members and staffs.
 Each book has BookID(Attribute), Title, one or more Authors, Publisher Year of Publication, ISBN and Price.
 Each Member has MemeberID(Attribute), Name, Address, Phone number.
 Each Staff has StaffID(Attribute), Name, Address, Phone number.
 Each Author has AuthorID(Attribute), Name, Address, Phone number.
 Each Publisher has PublisherID(Attribute), Name, Address, Phone number.
Use the above DTD in a sample XML document.
Code:

<?xml version="1.0"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="Book">

<xs:complexType>

<xs:sequence>

<xs:element name="b_id" type="xs:int"/>

<xs:element name="b_author" type="xs:string"/>

<xs:element name="b_title" type="xs:string"/>

<xs:element name="b_publisher" type="xs:int"/>

<xs:element name="b_year" type="xs:int"/>

<xs:element name="b_isbn" type="xs:int"/>

<xs:element name="b_price" type="xs:int"/>

</xs:sequence>

Siddartha Institute of Science and Technology Page 34


WEB AND INTERNET TECHNOLOGIES LABORATORY

</xs:complexType>

</xs:element>

<xs:element name="Member">

<xs:complexType>

<xs:sequence>

<xs:element name="m_id" type="xs:int"/>

<xs:element name="m_name" type="xs:string"/>

<xs:element name="m_address" type="xs:string"/>

<xs:element name="m_phone" type="xs:int"/>

</xs:sequence>

</xs:complexType>

</xs:element>

<xs:element name="Staff">

<xs:complexType>

<xs:sequence>

<xs:element name="s_id" type="xs:int"/>

<xs:element name="s_name" type="xs:string"/>

<xs:element name="s_address" type="xs:string"/>

<xs:element name="s_phone" type="xs:int"/>

</xs:sequence>

</xs:complexType>

</xs:element>

<xs:element name="Author">

<xs:complexType>

<xs:sequence>

<xs:element name="a_id" type="xs:int"/>

<xs:element name="a_name" type="xs:string"/>

<xs:element name="a_address" type="xs:string"/>

<xs:element name="a_phone" type="xs:int"/>

</xs:sequence>

</xs:complexType>

</xs:element>

Siddartha Institute of Science and Technology Page 35


WEB AND INTERNET TECHNOLOGIES LABORATORY

<xs:element name="Publisher">

<xs:complexType>

<xs:sequence>

<xs:element name="p_id" type="xs:int"/>

<xs:element name="p_name" type="xs:string"/>

<xs:element name="p_addresss" type="xs:string"/>

<xs:element name="p_phone" type="xs:int"/>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

Output:

17. Create a DTD to describe a bank that has one or more customers, accounts or Employee.
 Each Customer has a Customer ID, Name and address.
 Each account has an account ID, BranchID, CustomerID, AccountType and Balance.
 Each Employee has an EmpID, Name, Designation, DOJ, Salary and Address.
Use this DTD in a XML file.
Code:

bank.xml: It contains elements such as customer, account and employees.

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE Bank SYSTEM "bank.dtd">

<BankDetails>

<Bank>

<Customer>

<c_id>1001</c_id>

<c_name>Bill Gates</c_author>

<c_address>USA</c_title>

</Customer>

<Account>

Siddartha Institute of Science and Technology Page 36


WEB AND INTERNET TECHNOLOGIES LABORATORY

<a_id>1</m_id>

<br_id>2803</br_id>

<c_id>1001</c_id>

<a_type>savings</a_type>

<a_bal>20000</a_bal>

</Account>

<Employee>

<e_id>2</e_id>

<e_name>Rakul</e_name>

<e_desingation>cashier</e_desingation>

<e_doj>23-10-2010</s_doj>

<e_salary>80000</e_salary>

<e_address>Puttur</e_address>

</Employee>

</Bank>

<Bank>

<Customer>

<c_id>1002</c_id>

<c_name>Modi</c_author>

<c_address>Delhi</c_title>

</Customer>

<Account>

<a_id>2</m_id>

<br_id>2803</br_id>

<c_id>1002</c_id>

<a_type>savings</a_type>

<a_bal>50000</a_bal>

</Account>

<Employee>

<e_id>3</e_id>

<e_name>sekhar</e_name>

<e_desingation>cashier</e_desingation>

Siddartha Institute of Science and Technology Page 37


WEB AND INTERNET TECHNOLOGIES LABORATORY

<e_doj>23-08-2008</s_doj>

<e_salary>100000</e_salary>

<e_address>Tirupathi</e_address>

</Employee>

</Bank>

</BankDetails>

Bank.dtd: It verifies validness of bank.xml file.

<!ELEMENT BankDetails (Book+)>

<!ELEMENT Bank (Customer,Account,Employee)>

<!ELEMENT Customer(c_id,c_name,c_address)>

<!ELEMENT c_id (#PCDATA)>

<!ELEMENT c_name (#PCDATA)>

<!ELEMENT c_address (#PCDATA)>

<!ELEMENT Account (a_id,br_id,c_id,a_type,a_bal)>

<!ELEMENT a_id (#PCDATA)>

<!ELEMENT br_id (#PCDATA)>

<!ELEMENT c_id (#PCDATA)>

<!ELEMENT a_type (#PCDATA)>

<!ELEMENT a_bal (#PCDATA)>

<!ELEMENT Employee(e_id,e_name,e_designation,e_doj,e_salary,e_address)>

<!ELEMENT e_id (#PCDATA)>

<!ELEMENT e_name (#PCDATA)>

<!ELEMENT e_designation (#PCDATA)>

<!ELEMENT e_doj (#PCDATA)>

<!ELEMENT e_salary (#PCDATA)>

<!ELEMENT e_address (#PCDATA)>

Output:

Siddartha Institute of Science and Technology Page 38


WEB AND INTERNET TECHNOLOGIES LABORATORY

18. Create Schema describe a bank that has one or more customers, accounts or depositors. Use the
previous questions details. Also show a sample instance XML document.
Code:

bank.xsd:

<?xml version="1.0"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="BankDetails / Bank">

<xs:element name="Customer">

<xs:complexType>

<xs:sequence>

<xs:element name="c_id" type="xs:int"/>

<xs:element name="c_name" type="xs:string"/>

<xs:element name="c_address" type="xs:string"/>

Siddartha Institute of Science and Technology Page 39


WEB AND INTERNET TECHNOLOGIES LABORATORY

</xs:sequence>

</xs:complexType>

</xs:element>

<xs:element name="Account">

<xs:complexType>

<xs:sequence>

<xs:element name="a_id" type="xs:int"/>

<xs:element name="br_id" type="xs:int"/>

<xs:element name="c_id" type="xs:int"/>

<xs:element name="a_type" type="xs:string"/>

<xs:element name="a_bal" type="xs:int"/>

</xs:sequence>

</xs:complexType>

</xs:element>

<xs:element name="Employee">

<xs:complexType>

<xs:sequence>

<xs:element name="e_id" type="xs:int"/>

<xs:element name="e_name" type="xs:string"/>

<xs:element name="e_designation" type="xs:string"/>

<xs:element name="e_doj" type="xs:date"/>

<xs:element name="e_salary" type="xs:int"/>

<xs:element name="e_address" type="xs:string"/>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

Output:

Siddartha Institute of Science and Technology Page 40


WEB AND INTERNET TECHNOLOGIES LABORATORY

Siddartha Institute of Science and Technology Page 41

Você também pode gostar