Вы находитесь на странице: 1из 47

Name- Sourav seal

Roll- 16500116014

-1-
Name- Sourav seal
Roll- 16500116014

Name: Sourav Seal


Semester: 7th
University Roll: 16500116014
Subject: Internet Technology
Code: CS 795A

-2-
Name- Sourav seal
Roll- 16500116014

Contents

-3-
Name- Sourav seal
Roll- 16500116014

HTML
1. Start your web page with an <html> tag
i) Add a heading.
ii) Add a title.
iii) Start the <body> section.
iv) Add the following text using <H1> and </H1> tags: This Web page was designed by (your name)
v) Add the following text using <H2> and </H2> tags: My HTML assignment
vi) Add a horizontal line
vii) Insert an image to your web page. Note: You should then refer to your image with just the filename,
and NOT the entire pathname to the file.
viii) Add another horizontal line.
ix) Enter a paragraph of text. Write about things you have learned in html. Make sure the text in this
paragraph is a color other than black, but something one can see. Add a link that takes you to your
favorite webpage.
x) Start a new paragraph. Add a three item ordered list. Make it creative (don’t just say item 1, item 2,
etc... and keep it clean)!
xi) Close out your body and html tags.
--------------------------------------------------------------------------------------------

<!DOCTYPE html>
<html>
<head>
<title>first web page </title>
<h1>question 1</h1>

</head>
<body>
<h1>The web page was designed by sourav seal</h1>
<h2>my html document</h2>
<hr>
<img src="pic1.png" alt="pic1">
<hr>
<p style="color: red; text-align: ">html is a markup language used as a static web page<br>
this is very interesting.
<a href="https://www.w3schools.com/html/">hello</a>
</p>
<p>
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</p>

</body>

-4-
Name- Sourav seal
Roll- 16500116014
</html>

2) Start your web page with an &lt;html&gt; tag


i) Add a heading.
ii) Add a title.
iii) Start the &lt;body&gt; section.
iv) Start a new paragraph. Use alignment attribute, Use bold, italic, underline tags.Use font tag and
associated attributes, Use heading tags, Use preserve tag, Use non breaking spaces (escape character).

<!DOCTYPE html>
<html>
<head>
<title>second web page </title>
<h1>question 2</h1>
<style>
p{
font-family: "Times New Roman", Times, serif;
text-align: center;
font-style: italic;
font-size: 15px;
color: green;

}
</style>

-5-
Name- Sourav seal
Roll- 16500116014
</head>
<body>
<h1>The web page was designed by sourav seal</h1>
<h2>my html document</h2>
<hr>
<p> html is a markup language used as a static web page<br>
<u>this is very interesting.</u>
&nbsp 10
</p>
<pre>hiiii
hshs </pre>
</body>
</html>

3. Start your web page with an &lt;html&gt; tag


i) Add a heading.
ii) Add a title.
iii) Start the &lt;body&gt; section.
iv) Start a new paragraph. Create Hyperlinks:
(a) Within the HTML document.
(b) To another URL.
(c) To a file that can be rendered in the browser.

<!DOCTYPE html>
<html>
<head>

-6-
Name- Sourav seal
Roll- 16500116014
<title>third web page </title>
<h1>question 3</h1>
<style>
p{
font-family: "Times New Roman", Times, serif;
text-align: center;
font-style: italic;
font-size: 15px;
color: green;

}
</style>
</head>
<body>
<h1>The web page was designed by sourav seal</h1>
<h2>my html document</h2>
<hr>
<a name="start">
<p><a href="#start">link text1</a> <br>
<a href="www.w3schools.com">link text2</a><br>
<a href="ques2.html">link text3</a><br>
</p>
</body>
</html>

4. Start your web page with an &lt;html&gt; tag


i) Add a heading.
ii) Add a title.
iii) Start the &lt;body&gt; section. Create an unordered list, Create an ordered list, Use various bullet styles,
Created nested lists, Create definition lists, Use graphics as bullets.
-7-
Name- Sourav seal
Roll- 16500116014
<!DOCTYPE html>
<html>
<head>
<title>!!problem_statement_4!!</title>
<h1>problem_statement_4</h1>
</head>
<style>
body {
background-color: lightblue;
}
</style>
<body>

<h2>--unordered list--</h2>
<ul style="list-style-type:disc;">
<li>fruits</li>
<li>flowers</li>
<li>trees</li>
</ul>

<h2>--ordered list--</h2>
<ol type="I">
<li>Mango</li>
<li>Lily</li>
<li>Banyan Tree</li>
</ol>

<h2>--nested list--</h2>
<ul style="list-style-type: square;">
<li>FRUITS</li>
<li>FLOWERS
<ul style="list-style-type: circle;">
<li>Jasmine</li>
<li>Rose</li>
</ul>
</li>
<li>TREES</li>
</ul>

<h2>--definition list--</h2>
<dl>
<dt>Jasmine</dt>
<dd><img src="cm.gif" width="26" height="14"> White coloured flower</dd>
<dt>Rose</dt>
<dd><img src="cm.gif" width="26" height="14"> Red coloured flower</dd>
</dl>
</body>
</html>
-8-
Name- Sourav seal
Roll- 16500116014

5. Start your web page with an &lt;html&gt; tag


i) Add a heading.
ii) Add a title.
iii) Start the &lt;body&gt; section.
a) Create a simple table Create borders and adjust border size. Adjust table cell spacing. Change border
color. Change table background color
b) Align a new table on HTML page. Perform cell text alignment, Create multi-column tables, Display
information about your academic qualification into this table.

(a)
<!DOCTYPE html>
<html>
<head>fifth web page </title>
<h1>question 5</h1>
<style type="text/css">
table, th, td {
border: 1px solid blue;

}
</style>
</head>
<body>
<table style="width:100%;background-color: yellow">
<tr>
<th>Firstname</th>
<th>Lastname</th>

-9-
Name- Sourav seal
Roll- 16500116014
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
</body>
</html>

(b)
<!DOCTYPE html>
<html>
<head>
<title>!!problem_statement_5(b)!!</title>
<h1>problem_statement_5(b)</h1>
</head>

<style>
table, th, td {
border: 2px solid black ;
background-color: yellow;
}
th, td {
padding: 10px;
text-align: left;
}
</style>
<body>
<h2>--ACADEMIC RECORDS--</h2>
<table style="width:100%">
<tr>
<th>Name</th>

- 10 -
Name- Sourav seal
Roll- 16500116014
<th>School</th>
<th>College</th>
<th colspan="2">Marks(%) in school</th>
<th colspan="3">Marks(%) in college</th>
</tr>
</tr>
<tr>
<td>SOURAV SEAL</td>
<td>ST.STEPHEN'S SCHOOL</td>
<td>CIEM</td>
<td>10th- 96%</td>
<td>12th- 94%</td>
<td>1st year- 8.68</td>
<td>2nd year- 8.39</td>
<td>3rd year- 9.12</td>
</tr>

</body>
</html>

- 11 -
Name- Sourav seal
Roll- 16500116014

JavaScript
Problem statement:
Prompt, alert, array, looping in JavaScript.
Prompt Box
A prompt box is often used if you want the user to input a value before entering a page. When a prompt box pops
up, the user will have to click either "OK" or "Cancel" to proceed after entering an input value. If the user clicks
"OK" the box returns the input value. If the user clicks "Cancel" the box returns null.
<html>
<body>
<p>Click the button to demonstrate the prompt box.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction()
{
var x;

var person=prompt("Please enter your name","Harry Potter");

if (person!=null)
{
x="Hello " + person + "! How are you today?";
document.getElementById("demo").innerHTML=x;
}
}
</script>

</body>
</html>

<!DOCTYPE html>
<html>
<body>

<h1 id="header">Old Header</h1>

<script>
var element=document.getElementById("header");
element.innerHTML="New Header";
</script>

</body>
</html>
Output:

- 12 -
Name- Sourav seal
Roll- 16500116014

Alert Box
An alert box is often used if you want to make sure information comes through to the user.When an alert box
pops up, the user will have to click "OK" to proceed.
Syntax
<html>
<head>
<script>
function myFunction()
{
alert("Hello! I am an alert box!");
}
</script>
</head>
<body>

<input type="button" onclick="myFunction()" value="Show alert box" />

</body>
</html>
Output:

Array
Create an Array
An array can be created in three ways.
- 13 -
Name- Sourav seal
Roll- 16500116014
The following code creates an Array object called myCars:
1: Regular:
var myCars=new Array();
myCars[0]="Saab";
myCars[1]="Volvo";
myCars[2]="BMW";
2: Condensed:
var myCars=new Array("Saab","Volvo","BMW");
3: Literal:
var myCars=["Saab","Volvo","BMW"];

Syntax
<html>
<body>

<script>
var i;
var mycars = new Array();
mycars[0] = "Saab";
mycars[1] = "Volvo";
mycars[2] = "BMW";

for (i=0;i<mycars.length;i++)
{
document.write(mycars[i] + "<br>");
}
</script>

</body>
</html>

Output:

Saab
Volvo
BMW
Different Kinds of Loops
JavaScript supports different kinds of loops:
 for - loops through a block of code a number of times
 for/in - loops through the properties of an object
 while - loops through a block of code while a specified condition is true
 do/while - also loops through a block of code while a specified condition is true
The For Loop
The for loop is often the tool you will use when you want to create a loop.
The for loop has the following syntax:
for (statement 1; statement 2; statement 3)
{
the code block to be executed
}
- 14 -
Name- Sourav seal
Roll- 16500116014
Statement 1 is executed before the loop (the code block) starts.
Statement 2 defines the condition for running the loop (the code block).
Statement 3 is executed each time after the loop (the code block) has been executed.
Example
for (var i=0; i<5; i++)
{
x=x + "The number is " + i + "<br>";
}

Example

<html>
<body>

<p>Click the button to loop through a block of code five times.</p>


<button onclick="myFunction()">Try it</button>
<p id="demo"></p>

<script>
function myFunction()
{
var x="";
for (var i=0;i<5;i++)
{
x=x + "The number is " + i + "<br>";
}
document.getElementById("demo").innerHTML=x;
}
</script>

</body>
</html>
Output:

Click the button to loop through a block of code five times.


Try it
The number is 0
The number is 1
The number is 2
The number is 3
The number is 4

The For/In Loop


The JavaScript for/in statement loops through the properties of an object:
Example
var person={fname:"John",lname:"Doe",age:25};

for (x in person)
{
- 15 -
Name- Sourav seal
Roll- 16500116014
txt=txt + person[x];
}

Example

<html>
<body>
<p>Click the button to loop through the properties of an object named "person".</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>

<script>
function myFunction()
{
var x;
var txt="";
var person={fname:"John",lname:"Doe",age:25};

for (x in person)
{
txt=txt + person[x];
}

document.getElementById("demo").innerHTML=txt;
}
</script>
</body>
</html>
The While Loop
The while loop loops through a block of code as long as a specified condition is true.
Syntax
while (condition)
{
code block to be executed
}
Example
The loop in this example will continue to run as long as the variable i is less than 5:
while (i<5)
{
x=x + "The number is " + i + "<br>";
i++;
}
Example
<html>
<body>

<p>Click the button to loop through a block of as long as <em>i</em> is less than 5.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>

- 16 -
Name- Sourav seal
Roll- 16500116014

<script>
function myFunction()
{
var x="",i=0;
while (i<5)
{
x=x + "The number is " + i + "<br>";
i++;
}
document.getElementById("demo").innerHTML=x;
}
</script>

</body>
</html>
The Do/While Loop
The do/while loop is a variant of the while loop. This loop will execute the code block once, before checking if
the condition is true, then it will repeat the loop as long as the condition is true.
Syntax
do
{
code block to be executed
}
while (condition);
Example
<!DOCTYPE html>
<html>
<body>

<p>Click the button to loop through a block of as long as <em>i</em> is less than 5.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>

<script>
function myFunction()
{
var x="",i=0;
do
{
x=x + "The number is " + i + "<br>";
i++;
}
while (i<5)
document.getElementById("demo").innerHTML=x;
}
</script>

</body>

- 17 -
Name- Sourav seal
Roll- 16500116014
</html>

Problem statement:
Validate the fields of a form using JavaScript.
PROGRAM:
<html>
<head>
<title>REGISTRATION FORM</title>
<SCRIPT language="JavaScript">
function validate()
{
var uname;
var cpwd;
var rpwd;
var email;

uname=document.myform.username.value;
cpwd=document.myform.password.value;
rpwd=document.myform.repassword.value;
email=document.myform.email.value;

if(uname=="")
{
alert("Login name can not be blank.");
return false;
}
if(uname.substring(0,1)>0||uname.substring(0,1)<9)
{
alert("Do not use digits at first.");
return;
}
if(uname.substring(0,1)=='_')
{
alert("Do not use '_' at first character.");
return;
}
if(cpwd=="")
{
alert("Password can not be blank.");
return;
}

if(rpwd=="")
{
alert("Retype Password can not be blank.");
return;
}

- 18 -
Name- Sourav seal
Roll- 16500116014
if(cpwd.length<4 || cpwd.length>10)
{
alert("For password enter atleast 4 but upto 10 characters.");
return;
}
if(cpwd !=rpwd)
{
alert("Re-type Password and Password are not same.");
return;
}

//for varify email


var atpos=email.indexOf("@");
var dotpos=email.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=email.length)
{
alert("Not a valid e-mail address");
return false;
}

document.myform.action="verify.html";
document.myform.submit();
}
</SCRIPT>
</head>

<body bgcolor="#999966">
<h2 align="center"><u>REGISTRATION FORM</u></h2>

<form method="post" name="myform" >


<table>
<tr><td><p><font color="#800000" size="5">User Name:</font></p></td>
<td><input type="text" name="username" size="20"></td></tr>

<tr><td><p><font color="#800000" size="5">Enter your password:</font></p></td>


<td><input type="password" name="password" size="20"></td></tr>

<tr><td><p><font color="#800000" size="5">Retype Your Password:</font></p></td>


<td><input type="password" name="repassword" size="20"></td></tr>

<tr><td><p><font color="#800000" size="5">Email ID:</font></p></td>


<td><input type="text" name="email" size="20"></td></tr>

<tr><td></td><td><input type="submit" value="REGISTER" onClick="validate();"></td></tr>


</table>
</form>
</body>
</html>

- 19 -
Name- Sourav seal
Roll- 16500116014
Output:

Problem statement:
1. Guess a number based on user input.
2. Program on image rollover using JavaScript.
For Guess a number based on user input.
PROGRAM:
<html>
<body>
<script>
var x = Math.floor(Math.random() * 100) + 1;
var turns = 5;
var hint = 'Guess my number, 1-100!';

while (turns > 0) {


var guess = prompt(hint +
' You have ' + turns + ' guesses left.');
if (!guess) break;
guess = Number(guess);
if (guess == x) {
document.write('<p>YOU WIN!</p>' +
'<p><img src="/images/photo/gold_trophy.jpg">');
turns = 0;
} else {
hint = 'Nope.';
if (guess < x) hint += ' Too small!';
if (guess > x) hint += ' Too big!';
turns = turns - 1;
}
}
alert('The secret number was ' + x + '.');
</script>
</body>
</html>

- 20 -
Name- Sourav seal
Roll- 16500116014

Code for image rollover using JavaScript.

<html>
<head>
<script language="javascript">
function roll()
{
document.getElementById("a").src="p3.jpg";
}
</script>
</head>
<body>
<img src="p4.jpg" id="a" onMouseOver="roll()" onMouseOut="this.src='p4.jpg'">
</body>
</html>

Problem statement:
Calculator using JavaScript.
- 21 -
Name- Sourav seal
Roll- 16500116014
Code for simple calculator:
PROGRAM:
<html>

<head>

<title>Simple Javascript Calculator - Basic Arithmetic Operations</title>

<script language="javascript" type="text/javascript">


function multiply(){
a=Number(document.calculator.number1.value);
b=Number(document.calculator.number2.value);
c=a*b;
document.calculator.total.value=c;
}
</script>

<script language="javascript" type="text/javascript">


function addition(){
a=Number(document.calculator.number1.value);
b=Number(document.calculator.number2.value);
c=a+b;
document.calculator.total.value=c;
}
</script>

<script language="javascript" type="text/javascript">


function subtraction(){
a=Number(document.calculator.number1.value);
b=Number(document.calculator.number2.value);
c=a-b;
document.calculator.total.value=c;
}
</script>

<script language="javascript" type="text/javascript">


function division(){
a=Number(document.calculator.number1.value);
b=Number(document.calculator.number2.value);
c=a/b;
document.calculator.total.value=c;
}
</script>

<script language="javascript" type="text/javascript">


function modulus(){
a=Number(document.calculator.number1.value);
b=Number(document.calculator.number2.value);

- 22 -
Name- Sourav seal
Roll- 16500116014
c=a%b;
document.calculator.total.value=c;
}
</script>

</head>

<body>

<!-- Opening a HTML Form. -->


<form name="calculator">

<!-- Here user will enter 1st number. -->


Number 1: <input type="text" name="number1">

<!-- Here user will enter 2nd number. -->


Number 2: <input type="text" name="number2">

<!-- Here result will be displayed. -->


Get Result: <input type="text" name="total">

<!-- Here respective button when clicked, calls only respective artimetic function. -->
<input type="button" value="ADD" onclick="javascript:addition();">
<input type="button" value="SUB" onclick="javascript:subtraction();">
<input type="button" value="MUL" onclick="javascript:multiply();">
<input type="button" value="DIV" onclick="javascript:division();">
<input type="button" value="MOD" onclick="javascript:modulus();">

</form>

</body>
</html>

Output:

- 23 -
Name- Sourav seal
Roll- 16500116014

Code for complex calculator:


PROGRAM:
<html>
<head>
<title>Calculator</title>
<script language="javascript">
var i,j,op1,op2,op,f;
function digit(i)
{
switch(i)
{
case 1:
document.calc.display.value=(document.calc.display.value)+"1";
break;
case 2:
document.calc.display.value=(document.calc.display.value)+"2";
- 24 -
Name- Sourav seal
Roll- 16500116014
break;
case 3:
document.calc.display.value=(document.calc.display.value)+"3";
break;
case 4:
document.calc.display.value=(document.calc.display.value)+"4";
break;
case 5:
document.calc.display.value=(document.calc.display.value)+"5";
break;
case 6:
document.calc.display.value=(document.calc.display.value)+"6";
break;
case 7:
document.calc.display.value=(document.calc.display.value)+"7";
break;
case 8:
document.calc.display.value=(document.calc.display.value)+"8";
break;
case 9:
document.calc.display.value=(document.calc.display.value)+"9";
break;
case 0:
document.calc.display.value=(document.calc.display.value)+"0";
break;
case 10:
document.calc.display.value=(document.calc.display.value)+".";
break;
}
}
function operation(j)
{
if(j==1)
{
op1=parseFloat(document.calc.display.value);
document.calc.display.value="";
op=1;
}
if(j==2)
{
op1=parseFloat(document.calc.display.value);
document.calc.display.value="";
op=2;
}
if(j==3)
{
op1=parseFloat(document.calc.display.value);
document.calc.display.value="";
op=3;

- 25 -
Name- Sourav seal
Roll- 16500116014
}
if(j==4)
{
op1=parseFloat(document.calc.display.value);
document.calc.display.value="";
op=4;
}
if(j==5)
{
op2=parseFloat(document.calc.display.value);
if(op==1)
{
f=op1+op2;
document.calc.display.value=f;
}
else if(op==2)
{
f=op1-op2;
document.calc.display.value=f;
}
else if(op==3)
{
f=op1*op2;
document.calc.display.value=f;
}
else if(op==4)
{
f=op1/op2;
document.calc.display.value=f;
}
}
}
</script>
</head>
<body>
<form name="calc">
<table align="center" bgcolor="black" cellspadding=5 cellspacing=5 height=200 width=200>
<tr>
<td colspan=4 align="center">
<input type="text" name="display">
</td>
</tr>
<tr>
<td>
<input type="button" name="B" value=" 7 " onClick="digit(7)">
</td>
<td>
<input type="button" name="B" value=" 8 " onClick="digit(8)">
</td>

- 26 -
Name- Sourav seal
Roll- 16500116014
<td>
<input type="button" name="B" value=" 9 " onClick="digit(9)">
</td>
<td>
<input type="button" name="B" value=" + " onClick="operation(1)">
</td>
</tr>
<tr>
<td>
<input type="button" name="B" value=" 4 " onClick="digit(4)">
</td>
<td>
<input type="button" name="B" value=" 5 " onClick="digit(5)">
</td>
<td>
<input type="button" name="B" value=" 6 " onClick="digit(6)">
</td>
<td>
<input type="button" name="B" value=" - " onClick="operation(2)">
</td>
</tr>
<tr>
<td>
<input type="button" name="B" value=" 1 " onClick="digit(1)">
</td>
<td>
<input type="button" name="B" value=" 2 " onClick="digit(2)">
</td>
<td>
<input type="button" name="B" value=" 3 " onClick="digit(3)">
</td>
<td>
<input type="button" name="B" value=" * " onClick="operation(3)">
</td>
</tr>
<tr>
<td>
<input type="button" name="B" value=" 0 " onClick="digit(0)">
</td>
<td>
<input type="button" name="B" value=" . " onClick="digit(10)">
</td>
<td>
<input type="button" name="B" value=" = " onClick="operation(5)">
</td>
<td>
<input type="button" name="B" value=" / " onClick="operation(4)">
</td>
</tr>

- 27 -
Name- Sourav seal
Roll- 16500116014
</table>
</center>
</form>
</body>
</html>
Output:

- 28 -
Name- Sourav seal
Roll- 16500116014

Problem statement:
Display clock using JavaScript.

Code for Display clock using JavaScript.(Digital Clock)


PROGRAM: (Suggested code not to be given to the students)
<HTML>
<HEAD>
<TITLE> Digital Clock </TITLE>
<script type="text/javascript">

function updateClock ( )
{
var currentTime = new Date ( );

var currentHours = currentTime.getHours ( );


var currentMinutes = currentTime.getMinutes ( );
var currentSeconds = currentTime.getSeconds ( );

// Pad the minutes and seconds with leading zeros, if required


currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;

// Choose either "AM" or "PM" as appropriate


var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";

// Convert the hours component to 12-hour format if needed


currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;

// Convert an hours component of "0" to "12"


currentHours = ( currentHours == 0 ) ? 12 : currentHours;

// Compose the string for display


var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;
- 29 -
Name- Sourav seal
Roll- 16500116014

// Update the time display


document.getElementById("clock").innerHTML = currentTimeString;
}
</script>

</HEAD>

<BODY onload="updateClock(); setInterval('updateClock()', 1000 )">


<div id="clock"> </div>
</BODY>
</HTML>
Output:

- 30 -
Name- Sourav seal
Roll- 16500116014

XML
Xml delaration:
<?xml version="version_number" encoding="encoding_declaration"
standalone="standalone_status" ?>
 The XML declaration has no closing tag, that is </?xml>
The following table shows a list of the possible attributes that may be used in the XML declaration.
Attribute
Possible Attribute Value: Attribute Description:
Name:
Specifies the version of the XML standard that the XML
version 1.0 document conforms to. The version attribute must be
included if the XML declaration is declared.
UTF-8, UTF-16, ISO-10646-UCS-
These are the encoding names of the most common
2, ISO-10646-UCS-4, ISO-8859-1
encoding character sets in use today. For a full list of encodings
to ISO-8859-9, ISO-2022-JP,
check the IANA's website.
Shift_JIS, EUC-JP
Use 'yes' if the XML document has an internal DTD.
standalone yes, no Use 'no' if the XML document is linked to an external
DTD, or any external entity references.

Problem statement:
Write a XML program that will create an XML document which contains your mailing address.
PROGRAM: (Suggested code not to be given to the students)
<?xml version="1.0"?>
<email>
<from>rafe@rafe.us</from>
<to>someone@example.com</to>
<cc>someoneelse@example.com</cc>
<bcc>rafe@rafe.us</bcc>
<subject>This is the subject</subject>
<body>This is the body of an email message.</body>
</email>

Problem statement:
Write a XML program that will create an XML document which contains description of three book
category.
PROGRAM:
<?xml version="1.0"?>
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
- 31 -
Name- Sourav seal
Roll- 16500116014
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>

Problem statement:
Create an XML document that contains airline flight information.
i) In your XML document mention all properties of XML declaration.
ii) The root element has name <airlines>
iii) Create three nested <carrier> elements for three separate airlines. Each
element should include a name attribute.
iv) Within each <carrier> nest at least two <flight> ,each of which contains
parture_city, destination_ city, fl_no, dept_time.
v) Validate the document and if any parsing error is present fix them.
PROGRAM:
<?xml version="1.0"?>

<airlines>
<carrier name="Flight Information">
<flight>
<name>AIR INDIA</name>
<departure_city>From: KOLKATA</departure_city>
<destination_city>To: MUMBAI</destination_city>
<fl_no>Number: A3012</fl_no>
</flight>

<flight>
<name>INDIAN AIRLINES</name>
<departure_city>From: BANGALORE</departure_city>
<destination_city>To: KOLKATA</destination_city>
<fl_no>Number: B30003A</fl_no>
</flight>
<flight>
<name>JET AIRWAYS</name>
<departure_city>From: BANGKOK</departure_city>
<destination_city>To: KOLKATA</destination_city>
<fl_no>Number: C1125D</fl_no>
</flight>
</carrier>
</airlines>

- 32 -
Name- Sourav seal
Roll- 16500116014
Create an XML version of your resume. Include elements such as your name and position desired. Nest each of
your former employers within an <employer> element. Also, nest your educational experience within an
<education> element. Create any other nested elements that you deem appropriate, such as <references> or
<spcl_skills> elements.
PROGRAM:
<?xml version="1.0"?>
<resume>
<name>XYZ ABC</name>
<position_desired>MANAGER</position_desired>
<employer>
<employer1>Abc company</employer1>
<employer2>Xyz company</employer2>
<employer3>Def company</employer3>
</employer>
<education>
<exam>
<name>Madhyamic</name>
<year_of_passing>2003</year_of_passing>
<percentage>75.00%</percentage>
</exam>
<exam>
<name>Higher Secondary</name>
<year_of_passing>2005</year_of_passing>
<percentage>70.00%</percentage>
</exam>

<exam>
<name>B.Tech(IT)</name>
<year_of_passing>2009</year_of_passing>
<percentage>85.00%</percentage>
</exam>
</education>
<references>
<name1>abc</name1>
<name2>xyz</name2>
<name3>efg</name3>
</references>

<spcl_skills>
<skill1>Java,C++</skill1>
<skill2>French language</skill2>
</spcl_skills>
</resume>

Problem statement:
Write a xml file that include a css file

- 33 -
Name- Sourav seal
Roll- 16500116014
PROGRAM:
cd_catalog.css

CATALOG
{
background-color: #ffffff;
width: 100%;
}
CD
{
display: block;
display: block;
margin-bottom: 30pt;
margin-left: 0;
}
TITLE
{
color: #FF0000;
font-size: 20pt;
}
ARTIST
{
color: #0000FF;
font-size: 20pt;
}
COUNTRY,PRICE,YEAR,COMPANY
{
display: block;
color: #000000;
margin-left: 20pt;
}

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

<?xml-stylesheet type="text/css" href="cd_catalog.css"?>

<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</CD>
<CD>
<TITLE>Hide your heart</TITLE>
<ARTIST>Bonnie Tyler</ARTIST>

- 34 -
Name- Sourav seal
Roll- 16500116014
<COUNTRY>UK</COUNTRY>
<COMPANY>CBS Records</COMPANY>
<PRICE>9.90</PRICE>
<YEAR>1988</YEAR>
</CD>
</CATALOG>

Document Type Definition (DTD)


A Document Type Definition (DTD) defines the legal building blocks of an XML document. It defines the
document structure with a list of legal elements and attributes.
A DTD can be declared inline inside an XML document, or as an external reference.
Internal DTD Declaration
If the DTD is declared inside the XML file, it should be wrapped in a DOCTYPE definition with the following
syntax:
<!DOCTYPE root-element [element-declarations]>
Example XML document with an internal DTD:
<?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend</body>
</note>
(select "view source" or "view page source" to view the DTD)
The DTD above is interpreted like this:
 !DOCTYPE note defines that the root element of this document is note
 !ELEMENT note defines that the note element contains four elements: "to,from,heading,body"
 !ELEMENT to defines the to element to be of type "#PCDATA"
 !ELEMENT from defines the from element to be of type "#PCDATA"
 !ELEMENT heading defines the heading element to be of type "#PCDATA"
 !ELEMENT body defines the body element to be of type "#PCDATA"
External DTD Declaration
If the DTD is declared in an external file, it should be wrapped in a DOCTYPE definition with the following
syntax:
<!DOCTYPE root-element SYSTEM "filename">
This is the same XML document as above, but with an external DTD (Open it, and select view source):
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>

- 35 -
Name- Sourav seal
Roll- 16500116014
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
And this is the file "note.dtd" which contains the DTD:
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
PCDATA
PCDATA means parsed character data.
Think of character data as the text found between the start tag and the end tag of an XML element.
PCDATA is text that WILL be parsed by a parser. The text will be examined by the parser for entities
and markup.
Tags inside the text will be treated as markup and entities will be expanded.
However, parsed character data should not contain any &, <, or > characters; these need to be represented by the
&amp; &lt; and &gt; entities, respectively.
CDATA
CDATA means character data.
CDATA is text that will NOT be parsed by a parser. Tags inside the text will NOT be treated as markup and
entities will not be expanded.

Problem statement:
Create a DTD on product catalog.

PROGRAM:
<!DOCTYPE CATALOG [
<!ELEMENT CATALOG (PRODUCT+)>
<!ELEMENT PRODUCT (SPECIFICATIONS+, OPTIONS?, PRICE+, NOTES?)>
<!ELEMENT SPECIFICATIONS (#PCDATA)>
<!ELEMENT OPTIONS (#PCDATA)>
<!ELEMENT PRICE (#PCDATA)>
<!ELEMENT NOTES (#PCDATA)>

<!ATTLIST PRODUCT NAME CDATA #IMPLIED>


<!ATTLIST CATEGORY (HandTool | Table | Shop-Professional) "HandTool">
<!ATTLIST PARTNUM CDATA #IMPLIED>
<!ATTLIST PLANT (Pittsburgh | Milwaukee | Chicago) "Chicago">
<!ATTLIST INVENTORY (InStock | Backordered | Discontinued) "InStock">
<!ATTLIST SPECIFICATIONS WEIGHT CDATA #IMPLIED>
<!ATTLIST POWER CDATA #IMPLIED>
<!ATTLIST OPTIONS FINISH (Metal | Polished | Matte) "Matte">
<!ATTLIST OPTIONS ADAPTER (Included | Optional | NotApplicable) "Included">
<!ATTLIST OPTIONS CASE (HardShell | Soft | NotApplicable) "HardShell">
<!ATTLIST PRICE MSRP CDATA #IMPLIED>
<!ATTLIST PRICE WHOLESALE CDATA #IMPLIED>
<!ATTLIST PRICE STREET CDATA #IMPLIED>
<!ATTLIST PRICE SHIPPING CDATA #IMPLIED>

- 36 -
Name- Sourav seal
Roll- 16500116014

<!ENTITY AUTHOR "John Doe">


<!ENTITY COMPANY "JD Power Tools, Inc.">
<!ENTITY EMAIL "jd@jd-tools.com">
]>

- 37 -
Name- Sourav seal
Roll- 16500116014

Applet

1) Create a banner using Applet


import java.awt.*;
import java.applet.*;

public class NewApplet extends Applet implements Runnable {


String msg = " It is a moving Banner. ";
char cha;
boolean stopFlag = true;
Thread t = null;

public void start() {


t = new Thread(this);
stopFlag = false;
t.start();
}
public void run() {
for(;;) {
try {
repaint();
Thread.sleep(250);
cha = msg.charAt(0);
msg = msg.substring(1,msg.length());
msg = msg + cha;
if(stopFlag) break;
}
catch(InterruptedException e) {}
}
}
public void stop(){
stopFlag = true;
t = null;
}
public void paint(Graphics g) {
g.drawString(msg,60,30);
}
}

- 38 -
Name- Sourav seal
Roll- 16500116014
2) Display clock using Applet

import java.awt.*;
import java.applet.*;
import java.applet.*;
import java.awt.*;
import java.util.*;

public class ClockApplet extends Applet implements Runnable {


Thread t,t1;
public void start() {
t = new Thread(this);
t.start();
}
public void run() {
t1 = Thread.currentThread();
while(t1 == t) {
repaint();
try {
t1.sleep(1000);
}
catch(InterruptedException e){}
}
}
public void paint(Graphics g) {
Calendar cal = new GregorianCalendar();
String hour = String.valueOf(cal.get(Calendar.HOUR));
String minute = String.valueOf(cal.get(Calendar.MINUTE));
String second = String.valueOf(cal.get(Calendar.SECOND));
g.drawString(hour + ":" + minute + ":" + second, 20, 30);
}
}

3) Create different shapes using applet

import java.applet.*;
import java.awt.*;

public class Shapes extends Applet {


int x = 300, y = 100, r = 50;
public void paint(Graphics g) {
g.drawLine(30,300,200,10);
g.drawOval(x-r,y-r,100,100);
g.drawRect(400,50,200,100);

- 39 -
Name- Sourav seal
Roll- 16500116014
}
}

4) Fill colours in different shapes using applet

import java.applet.*;
import java.awt.*;

public class fillColor extends Applet {


public void paint(Graphics g) {
g.drawRect(300,150,200,100);
g.setColor(Color.yellow);
g.fillRect( 300,150, 200, 100 );
g.setColor(Color.magenta);
g.drawString("Rectangle",500,150);
}
}

5) Go to a link using Applet

import java.applet.*;
import java.awt.*;
import java.net.*;
import java.awt.event.*;

public class tesURL extends Applet implements ActionListener {


- 40 -
Name- Sourav seal
Roll- 16500116014
public void init() {
String link = "yahoo";
Button b = new Button(link);
b.addActionListener(this);
add(b);
}
public void actionPerformed(ActionEvent ae) {
Button src = (Button)ae.getSource();
String link = "http://www."+src.getLabel()+".com";

try {
AppletContext a = getAppletContext();
URL u = new URL(link);
a.showDocument(u,"_self");
} catch (MalformedURLException e){
System.out.println(e.getMessage());
}
}
}

6) Create an event listener in Applet

import java.applet.*;
import java.awt.event.*;
import java.awt.*;

public class EventListeners extends Applet implements ActionListener {


TextArea txtArea;
String Add, Subtract;
int i = 10, j = 20, sum = 0, Sub = 0;

public void init() {


txtArea = new TextArea(10,20);
txtArea.setEditable(false);
add(txtArea,"center");
Button b = new Button("Add");
Button c = new Button("Subtract");
b.addActionListener(this);
c.addActionListener(this);
add(b);
add(c);
}
public void actionPerformed(ActionEvent e) {
sum = i + j;
txtArea.setText("");
txtArea.append("i = "+ i + "\t" + "j = " + j + "\n");
Button source = (Button)e.getSource();

if(source.getLabel() == "Add") {
- 41 -
Name- Sourav seal
Roll- 16500116014
txtArea.append("Sum : " + sum + "\n");
}
if(i > j) {
Sub = i - j;
} else {
Sub = j - i;
}
if(source.getLabel() == "Subtract") {
txtArea.append("Sub : " + Sub + "\n");
}
}
}

7)Display image using Applet

import java.applet.*;
import java.awt.*;

public class appletImage extends Applet {


Image img;
MediaTracker tr;
public void paint(Graphics g) {
tr = new MediaTracker(this);
img = getImage(getCodeBase(), "demoimg.gif");
tr.addImage(img,0);
g.drawImage(img, 0, 0, this);
}
}

- 42 -
Name- Sourav seal
Roll- 16500116014

8)Open a link in a new window using Applet

import java.applet.*;
import java.awt.*;
import java.net.*;
import java.awt.event.*;

public class testURL_NewWindow extends Applet implements ActionListener {


public void init() {
String link_Text = "google";
Button b = new Button(link_Text);
b.addActionListener(this);
add(b);
}
public void actionPerformed(ActionEvent ae) {
Button source = (Button)ae.getSource();
String link = "http://www."+source.getLabel()+".com";

try {
AppletContext a = getAppletContext();
URL url = new URL(link);
a.showDocument(url,"_blank");
} catch (MalformedURLException e) {
System.out.println(e.getMessage());
}
}
}

- 43 -
Name- Sourav seal
Roll- 16500116014
9) Play sound using Applet

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class PlaySoundApplet extends Applet implements ActionListener {


Button play,stop;
AudioClip audioClip;

public void init() {


play = new Button(" Play in Loop ");
add(play);
play.addActionListener(this);
stop = new Button(" Stop ");
add(stop);
stop.addActionListener(this);
audioClip = getAudioClip(getCodeBase(), "Sound.wav");
}
public void actionPerformed(ActionEvent ae) {
Button source = (Button)ae.getSource();
if (source.getLabel() == " Play in Loop ") {
audioClip.play();
} else if(source.getLabel() == " Stop "){
audioClip.stop();
}
}
}

10) Read a file using Applet

import java.applet.*;
import java.awt.*;
import java.io.*;
import java.net.*;

public class readFileApplet extends Applet {


String fileToRead = "test1.txt";
StringBuffer strBuff;
TextArea txtArea;
Graphics g;

- 44 -
Name- Sourav seal
Roll- 16500116014
public void init() {
txtArea = new TextArea(100, 100);
txtArea.setEditable(false);
add(txtArea, "center");
String prHtml = this.getParameter("fileToRead");

if (prHtml != null) fileToRead = new String(prHtml);


readFile();
}
public void readFile(){
String line;
URL url = null;
try {
url = new URL(getCodeBase(), fileToRead);
}
catch(MalformedURLException e){}
try {
InputStream in = url.openStream();
BufferedReader bf = new BufferedReader(new InputStreamReader(in));
strBuff = new StringBuffer();
while((line = bf.readLine()) != null) {
strBuff.append(line + "\n");
}
txtArea.append("File Name : " + fileToRead + "\n");
txtArea.append(strBuff.toString());
} catch(IOException e) {
e.printStackTrace();
}
}
}

11) Write to a file using Applet

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.Applet;
import java.net.*;

public class WriteFile extends Applet {


Button write = new Button("WriteToFile");
Label label1 = new Label("Enter the file name:");
TextField text = new TextField(20);
- 45 -
Name- Sourav seal
Roll- 16500116014
Label label2 = new Label("Write your text:");
TextArea area = new TextArea(10,20);

public void init() {


add(label1);
label1.setBackground(Color.lightGray);
add(text);
add(label2);

label2.setBackground(Color.lightGray);
add(area);
add(write,BorderLayout.CENTER);

write.addActionListener(new ActionListener () {
public void actionPerformed(ActionEvent e) {
new WriteText();
}
});
}
public class WriteText {
WriteText() {
try {
String str = text.getText();

if(str.equals("")) {
JOptionPane.showMessageDialog(null, "Please enter the file name!");
text.requestFocus();
} else {
File f = new File(str);
if(f.exists()) {
BufferedWriter out = new BufferedWriter(new FileWriter(f,true));
if(area.getText().equals("")) {
JOptionPane.showMessageDialog (null,"Please enter your text!");
area.requestFocus();
} else {
out.write(area.getText());
if(f.canWrite()) {
JOptionPane.showMessageDialog(null, "Text is written in "+str);
text.setText("");
area.setText("");
text.requestFocus();
} else {
JOptionPane.showMessageDialog(null, "Text isn't written in
"+str);
}
out.close();
}
} else {
JOptionPane.showMessageDialog (null,"File not found!");
text.setText("");
text.requestFocus();
}
}
} catch(Exception x) {
x.printStackTrace();
}
}
}
}

- 46 -
Name- Sourav seal
Roll- 16500116014

- 47 -

Вам также может понравиться