Web Programming Notes
Web Programming Notes
UNIT 1
Origins: 1960s
B1TNET, which is an acronym for Because It’s Time NETwork, began at the City
University of New York
It was built initially to provide electronic mail and file transfers.
CSNET is an acronym for ComputerScience NETwork. Its initial purpose was to provide
electronic mail.
1990s
These names begin with the names ofthe host machine, followed by progressively larger
enclosing collection ofmachines, called domains.
1|Page VSISCM
They are called browsers because they allow the user to browse the resources available on
servers.
Mosaic was the first browser with a graphical user interface.
A browser is a client on the Web because it initiates the communication with a server, which
waits for a request from the client before doing anything.
In the simplest case, a browser requests a static document from a server.
2|Page VSISCM
The server locates the document among its servable documents and sends it to the browser,
which
displays it for the user.
Sometimes a browser directly requests the execution of a program stored on the server. The
output of the program is then returned to the browser.
Examples: Internet Explorer, Mozilla Firefox, Netscape Navigator, Google Chrome.
Opera etc.,
WEB SERVERS
Web servers are programs that provide documents to requesting browsers. Example: Apache
All the communications between a web client and a web server use the HTTP
When a web server begins execution, it informs the OS under which it is running & it runs
as a background process
A web client or browser, opens a network connection to a web server, sends information
requests and possibly data to the server, receives information from the server and closes the
connection.
The primary task of web server is to monitor a communication port on host machine, accept
HTTP commands through that port and perform the operations specified by the commands.
When the URL is received, it is translated into either a filename or a program name.
This program allows the site manager to set parameters for the server.
Under Windows XP and Vista, the IIS snap-in is accessed by going to Control Panel,
Administrative Tools, and IISAdmin.
3|Page VSISCM
Configuration files of the server. Such paths are called partial paths.
Example: http://wwwrnsit.ac.in/
1. HTTP method Domain part of the URL HTTP version
2. Header fields
3. Blank line
4. Message body
The following is an example of the first line of an HTTP request:
4|Page VSISCM
The format of a header field is the field name followed by a colon and the value of the field.
There are four categories of header fields:
A wildcard character, the asterisk (*). can be used to specify that part of a MIME type can be
anything.
SECURITY
Security is one of the major concerns in the Internet .The server system can be accessed easily
with basic hardware support, internet connection & web browser.
The client can retrieve very important information from the server. Similarly, the server system
can introduce virus on the client system. These viruses can destroy the hardware and software in
client. While programming the web, following requirements should be considered:
5|Page VSISCM
Privacy: it means message should be readable only to communicating parties and not to
intruder.
Integrity: it means message should not be modified during transmission.
Authentication: it means communicating parties must be able to know each other's identity
Non-repudiation: it means that it should be possible to prove that message was sent and
received properly.
Security can be provided using cryptographic algorithm. Ex: private key. Public key
Protection against viruses and worms is provided by antivirus software, which must be
updated frequently so that it can detect and protect against the continuous stream of new
viruses and worms.
Web programmers use several languages to create the documents that servers can provide to
browsers.
The most basic of these is XHTML, the standard mark-up language for describing how Web
documents should be presented by browsers. Tools that can be used without specific knowledge
of XHTML are available to create XHTML documents.
A plug-in is a program that can be integrated with a word processor to make it possible to use
the word processor to create XHTML. A filter converts a document written in some other format
to XHTML.
XML is a meta-mark-up language that provides a standard way to define new mark-up
languages.
6|Page VSISCM
HTML XHTML
HTML is much easier to write XHTML requires a level of discipline many
of us naturally resist
Huge number of HTML documents some older browsers have problems with
available on the Web, browsers will some parts of XHTML.
continue to support HTML as far as one can
see into the future.
HTML has few syntactic rules, and HTML XHTML has strict syntactic rules that
processors (e.g., browsers) do not enforce impose a consistent structure on all
the rules it does have. Therefore, HTML XHTML documents. Another significant
authors have a high degree of freedom to reason for using XHTML is that when you
use their own syntactic preferences to create create an XHTML document, its syntactic
documents. Because of this freedom, HTML Correctness can be checked, either by an
Documents lack consistency, both in low- XML browser or by a validation tool.
level syntax and in overall structure.
Used for displaying the data Used for describing the data
BASIC SYNTAX
o The fundamental syntactic units of HTML are called tags.
o In general, tags are used to specify categories of content
o The syntax of a tag is the tag's name surrounded by angle brackets (< and >).
Tag names must be written in all lowercase letters.
Most tags appear in pairs: an opening tag and a closing tag.
Every XHTML document must begin with an xml declaration element that simply
identifies the document as being one based on XML This element includes an attribute
that specifies the version number 1.0.
The xml declaration usually includes a second attribute, encoding, which specifies the
encoding used for the document [utf-8].
7|Page VSISCM
Following is the xml declaration element, which should be the first line of every XHTML
document:
Note that this declaration must begin in the first character position of the document file.
The xml declaration element is followed immediately by an SGML DOCTYPE command,
which specifies the particular SGML document-type definition (DTD) with which the
document complies, among other things.
The following command states that the document in which it is included complies with the
XHTML 1.0
Strict standard:
<html xmlns="http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd”>
An XHTML document must include the four tags <html>, <head>, <title> , and <body>
The <html> tag identifies the root element of the document. So, XHTML documents always
have an <html> tag immediately following the DOCTYPE command, and they always end
with the closing html tag, </html>.
The html element includes an attribute, xmlns, that specifies the XHTML namespace, as shown
in the following element:
Although the xmlns attribute’s value looks like a URL. it does not specify a document. It is
just a name that happens to have the form of a URL.
An XHTML document consists of two parts, named the head and the body.
8|Page VSISCM
PLEASE NOTE: From here onwards programming in XHTML will begin. Please add the
following compulsory document structure to all programs in the first 4 lines and skip the
simple <html> tag of first line because I have begun the coding part directly.
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtmlll/DTD/xhtml-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
Paragraphs:
<html>
<head>
<title> Paragraph </title>
</head>
<body>
<p> Paragraph 1 </p>
<p> Paragraph 2 </p>
<p> Paragraph 3 </p>
</body>
</html>
9|Page VSISCM
Sometimes it is desirable to preserve the white space in text—that is, to prevent the
browser from eliminating multiple spaces and ignoring embedded line breaks. This
can be specified with the <pre> tag.
<html>
<head>
<title> Pre Tag </title>
</head>
<body>
<pre> My Name is DIVYA K
I am from ISE Department
RNSIT, Bangalore
</pre>
</p>
</body>
</html>
Block Quotations:
The <blockquote> tag is used to make the contents look different from the surrounding text
10 | P a g e VSISCM
<html>
</head>
<body>
<blockquote>
<p> "Arise..
•! Awake..!!" </p>
</blockquote>
</pre>
</p>
<p><pre>
x<sub>2</sub><sup>3</sup> + y<sub>l</sub><sup>2</sup>
</pre></p>
</body>
11 | P a g e VSISCM
</html>
Horizontal Rules:
The parts of a document can be separated from each other, making the document
easier to read, by placing horizontal lines between them. Such lines are called
horizontal rules. The block tag that creates them is <hr/>.
The <hr /> tag causes a line break (ending the current line) and places a line across
the screen.
Note again the slash in the <hr /> tag, indicating that this tag has no content and no
closing tag.
<html>
<head>
</head>
12 | P a g e VSISCM
<body>
</html>
IMAGES
In this case, whatever is the message given to alt attribute, that would be displayed.
Another use of alt is -> when image display option has been disabled by user. The
option is normally disabled when the size ofthe image is huge and takes time for
downloading.
<html>
<head>
<title>display image</title>
13 | P a g e VSISCM
</head>
<body>
</body>
</html>
HYPERTEXT LINKS
Links:
■ Hyperlinks are the mechanism which allows the navigation from one page to another.
Ordered Lists:
14 | P a g e VSISCM
1. Ordered lists are lists in which the order of items is important. This orderedness of a list is
shown in the display of the list by the implicit attachment of a sequential value to the
beginning of each item. The default sequential values are Arabic numerals, beginning
with 1.
2. An ordered list is created within the block tag <ol>. The items are specified and displayed
just as are those in unordered lists, except that the items in an ordered list are preceded by
sequential values instead of bullets.
Definition Lists:
As the name implies, definition lists are used to specify lists of terms and their definitions, as in
glossaries. A
definition list is given as the content of a <dl> tag, which is a block tag. Each term to be defined
in the definition
list is given as the content of a <dt> tag. The definitions themselves are specified as the content
of <dd> tags.
The defined terms of a definition list are usually displayed in the left margin; the definitions are
usually shown
indented on the line or lines following the term.
15 | P a g e VSISCM
<html>
<head>
<title> Definition List </title>
</head>
<body>
<hl> South Indian Film Heroes </hl>
<dl>
<dt> Puneeth Rajkumar </dt>
<dd>Top in Kannada Film lndustry*/dd>
<dt> Mahesh Babu </dt>
<dd>Top in Telugu Film Industry*/dd>
<dt> Suriya </dt>
<html>
<head>
<title> Align and valign </title>
16 | P a g e VSISCM
</head>
<body>
<p>Table having entries with different alignments</p>
<table border="border">
<tr align = "center">
<th> </th>
<th> Puneeth Rajkumar </th>
<th> DarshanThoogudeep</th>
<th> Kichcha Sudeep </th>
</tr>
<tr>
<th> Ramya </th>
<td align = "left"> Akaash </td>
<td align = "center"> Datta </td>
<td align = "right"> Ranga </td>
</tr>
<tr>
<th> <br/>Rakshitha <br/><br/><br/></th>
<td> Appu </td>
<td valign = "top"> Kalasipalya </td>
<td valign = ”bottomH> Kaashi from village </td>
</tr>
</table>
</body>
</html>
17 | P a g e VSISCM
<html>
<head>
<title> cell spacing and cell padding </title>
</head>
<body>
<h3>Table with space = 10, pad = 50</h3>
<table border = "7" cellspacing = "10" cellpadding = "50">
<tr>
<td> Divya </td>
<td>Chethan </td>
</tr>
</table>
<h3>Table with space = 50, pad = 10</h3>
<table border = "7" cellspacing = "50“ cellpadding = "10">
<tr>
<td> Divya </td>
<td>Chethan </td>
</tr>
</table></body></html>
*****************************************************************************
18 | P a g e VSISCM
UNIT 2
FORMS
The most common way for a user to communicate information from a Web browser to the server
is through a
form. XHTML provides tags to generate the commonly used objects on a screen form. These
objects are called
controls or widgets. There are controls for single-line and multiple-line text collection,
checkboxes, radio
buttons, and menus, among others. All control tags are inline tags.
❖ Text Box
✓ It is a type of input which takes the text.
19 | P a g e VSISCM
✓ For any type of input, a name has to be provided which is done using name attribute.
The size of the text can be controlled using size attribute.
✓ Every browser has a limit on the number of characters it can collect. If this limit is exceeded,
the extra characters are chopped off. To prevent this chopping, maxlength attribute can be used.
When maxlength is used, users can enter only those many characters that is given as a value to
the attribute.
Table Sections:
1. Tables naturally occur in two and sometimes three parts: header, body, and footer. (Not
all tables have a natural footer.)
2. These three parts can be respectively denoted in XHTML with the thead, tbody, and tfoot
elements. The header includes the column labels, regardless of the number of levels in
those labels. The body includes the data of the table, including the row labels.
3. The footer, when it appears, sometimes has the column labels repeated after the body. In
some tables, the footer contains totals for the columns of data above.
4. A table can have multiple body sections, in which case the browser may delimit them
with horizontal lines that are thicker than the rule lines within a body section.\
20 | P a g e VSISCM
<html>
<head> <title> Menu </title>
</head>
<body>
<p>
RNSIT Branches - Information Science, Computer Science, Electronics, Electrical,
Mechanical
</p>
<form action = "">
<p>
<label><input type="checkbox" name='act" value="three"/>Aindritha</label>
<label><input type="checkbox" name="act" value="four"/>Radhika</label>
<label><input type=”checkbox" name="act" value="four"/>Rakshitha</label>
</p>
</form></body></html>
21 | P a g e VSISCM
During the creation of text area, it should be mentioned how many sentences can be
entered. This is done using rows attribute.
Similarly, it should also be mentioned how many characters can be entered in a line. This
is done using cols attribute.
If the value given to rows is exceeded i.e. if users enter sentences more than specified, the
scroll bar automatically appears.
<html>
<head>
<title> text area </title>
</head>
<body>
<form action=" ">
<h3> Enter your comments</h3>
<p>
<textarea name="feedback" rows="5" cols=”100">
</textarea>
</p>
</form>
</body>
</html>
22 | P a g e VSISCM
<html>
<head>
<title> action buttons </title>
</head>
<body>
<form action=" ">
<p>
<input type="SUBMlT" value="SUBMlT"/>
<input type="RESET'' value="RESET"/>
</p>
</form>
</body>
</html>
23 | P a g e VSISCM
<html>
<head>
<title> CompleteForm</title>
</head>
<body>
<hl>Registration Form</hl>
<form action=" ">
<p>
<label>Enter your email id:
<input type = "text" name = "myname" size = "24" maxlength = "25" />
</label>
</p>
<p>
<label>Enter the password:
<input type = "password" name = "mypass" size = "20" maxlength = "20" />
</label*
</p>
<p>Sex</p>
<p>
<label><input type="radio" name="act" value="one"/*MaIe</label>
<label><input type="radio" name="act" value="two"/*Female</label>
</p>
<p>Which of the following Accounts do you have?</p>
<p>
<label><input type="checkbox" name="act" value="one'/*Gmail</label>
<label><input type="checkbox" name="act" value=”two"/*Facebook</IabeI>
<label><input type="checkbox" name="act" value="three"/*Twitter</label*
<label><input type="checkbox" name="act" value="four"/*Google+</label>
</p>
24 | P a g e VSISCM
FRAMES
The browser window can be used to display more than one document at a time. The
window can be divided into rectangular areas, each of which is a frame. Each frame is
capable of displaying its own document.
Framesets:
25 | P a g e VSISCM
The number of frames and their layout in the browser window are specified with the
<frameset> tag.
A frameset element takes the place of the body element in a document. A document has
either a body or a frameset but cannot have both.
The <frameset> tag must have either a rows or a cols attribute, (or both)
To create horizontal frames, rows attribute is used.
To create vertical frames, cols attribute is used.
The values for these attributes can be numbers, percentages and asterisks.
<html>
<head>
<title>Frameset Cols</title>
</head>
<frameset cols = "25%,25%,25%,25%">
<frame src = "FrameColl.html"/>
<frame src = "FrameCol2.html'7>
<frame src = "FrameCoB.htmr/*
<frame src = "FrameCol4.html'7>
</frameset>
</html>
26 | P a g e VSISCM
< html>
<head>
<title>Frameset Rowsand cols</title>
</head>
<frameset rows = "50, 50” cols = "*,*,*">
<frame src = "FrameColl.html"/*
<frame src = "FrameCol2.html"/*
<frame src = "FrameCoB.html"/*
<frame src = "FrameCol4.htmlM/>
<frame src = "FrameRowl.html"/>
<frame src = "FrameRow2.htmr/>
</framset>
</html>
27 | P a g e VSISCM
<title>Frameset Rows</title>
</head>
<frameset rows =””>
<frame src = "FrameRowl.html"/>
<frame src = "FrameRow2.html'7>
</frameset>
</html>
28 | P a g e VSISCM
29 | P a g e VSISCM
hl
font-size: 50pt;
color Red;
</style>
</head>
<hl>Puneeth Rajkumar</hl>
</html>
30 | P a g e VSISCM
SELECTOR FORMS
Simple Selector Forms:
In case of simple selector, a tag is used. If the properties of the tag are changed, then it reflects at all the
places when used in the program. The selector can be any tag. If the new properties for a tag are not
mentioned within the rule list, then the browser uses default behaviour of a tag.
<html>
<head>
<title>Sample CSS</titIe>
<style type = "text/css">
P
{
font-family: 'Lucida Handwriting';
font-size: 5Opt;
color: Red;
}
</style>
</head>
<body>
<p>Puneeth Rajkumar</p>
<p>Mahesh Babu</p>
<p>Suriya</p>
</body>
</html>
31 | P a g e VSISCM
Class Selectors:
In class selector, it is possible to give different properties for different elements
<html>
<head>
<title>Sample CSS</title>
</head>
<hl style ="font-family: 'Lucida Handwriting'; font-size: 5Opt; color: Red;“>
Puneeth Rajkumar </hl>
</html>
Style = "Property 1: Valuel; Property2: Value2; Property3: Value3; .... Property.!!: Value.n;"
Document Style Specification:
<style type = "text/css">
Rule list
</styie>
Each style rule in a rule list has two parts: a selector, which indicates the tag or tags affected by
the rule, and a
list of property-value pairs. The list has the same form as the quoted list for inline style sheets,
except that it is
delimited by braces rather than double quotes. So, the form of a style rule is as follows:
Selector { Propertyl: Valuel; Property?: Value2; Property3: Value3; Property_n: Value_n;}
32 | P a g e VSISCM
Class Selectors:
In class selector, it is possible to give different properties for different elements
<html>
<head>
<title>Sample CSS</title>
<style type = "text/css">
p.one
{
font-family: 'Lucida Handwriting';
font-size: 25pt;
colon Red;
}
p.two
{
font-family: 'Monotype Corsiva';
font-size: 50pt;
colon green;
} </style>
</head>
<body>
<p class = "one">Puneeth Rajkumar</p>
<p class = ”two">Puneeth Rajkumar</p>
</body>
</html>
33 | P a g e VSISCM
Generic Selectors:
In case of generic selector, when the class is created, it would not be associated to any particular
tag. In other words, it is generic in nature.
<html>
<head>
<title>Sample CSS</title>
<style type = "text/css">
.one
{
font-family: 'Monotype Corsiva';
colon green;
}
</style>
</head>
<body>
<p class = "one">Puneeth Rajkumar</p>
<hl class = "one">Puneeth Rajkumar</hl>
<h6 class = "one''>Puneeth Rajkumar</h6>
</body>
</html>
34 | P a g e VSISCM
id Selectors:
An id selector allows the application of a style to one specific element.
<html>
<head>
<title>Sample CSS</title>
<style type = "text/css">
#one
{
font-family: 'lucida calligraphy’;
color: purple;
}
font-family: 'comic sans ms';
color: orange;
}
</style>
</head>
<body>
<p id = ''two''>Puneeth Rajkumar</p>
<hl id = "one">Puneeth Rajkumar</hl>
</body>
</html>
35 | P a g e VSISCM
Universal Selectors:
The universal selector, denoted by an asterisk (*), applies its style to all elements in a document.
<html>
<head>
<title>Sample CSS</title>
<style type = “text/css">
{
font-family: 'lucida calligraphy';
color purple;
}
</style>
</style>
</head>
<body>
<hl>Puneeth Rajkumar</hl>
<h2>Puneeth Rajkumar</h2>
<h3>Puneeth Rajkumar</h3>
<p>Puneeth Rajkumar</p>
</body>
</html>
36 | P a g e VSISCM
Pseudo Classes:
Pseudo class selectors are used if the properties are to be changed dynamically.
For example: when mouse movement happens, in other words, hover happens or focus
happens.
<html>
<head>
<title>Sample CSS</ti tle>
<style type = "text/css">
input:focus
{
font-family: lucida calligraphy';
color: purple;
font-size: 100;
}
input:hover
{
font-family: 'lucida handwriting';
color: violet;
font-size:40;
)
</style>
</head>
<body>
<form action = " ">
<p>
<label>
37 | P a g e VSISCM
NAME:
<input type = "text" />
</label>
</p>
</form>
</body>
</html>
■ A number value can be either an integer or a sequence of digits with a decimal point and can
be preceded by a sign ( + or-).
• Length values are specified as number values that are followed immediately by a two-character
abbreviation of a unit name. The possible unit names are px, for pixels; in, for inches; cm, for
centimeters; mm, for millimeters; pt, for points.
38 | P a g e VSISCM
■ Percentage values are used to provide a measure that is relative to the previously used measure
for a property value. Percentage values are numbers that are followed immediately by a percent
sign p).Percentage values can be signed. If preceded by a plus sign, the percentage is added to
the previous value; if negative, the percentage is subtracted.
The RGB values can be given either as decimal numbers between 0 and 255 or as percentages.
Hexadecimal numbers must be preceded with pound signs (#), as in I43AF00.
Font Properties:
The font-family property is used to specify a list of font names. The browser uses the first font in
the list that it supports.
generic family - a group of font families with a similar look (like "Serif" or
"Monospace")
font family - a specific font family (like "Times New Roman" or "Arial")
Serif Times New Roman Serif fonts have small lines at the ends on
Georgia some characters
39 | P a g e VSISCM
<!DOCTYPE html>
<html>
<head>
<style>
p.serif {
font-family: "Times New Roman", Times, serif;
}
p.sansserif {
font-family: Arial, Helvetica, sans-serif;
}
</style>
</head>
<body>
<h1>CSS font-family</h1>
<p class="serif">This is a paragraph, shown in the Times New Roman font.</p>
<p class="sansserif">This is a paragraph, shown in the Arial font.</p>
</body>
</html>
40 | P a g e VSISCM
Font-size Property:
Font-variants Property:
The font-variant property specifies whether or not a text should be displayed in a small-caps font.
Syntax:
font-variant: normal|small-caps|initial|inherit;
Font-style Property:
The font-style property specifies the font style for a text.
Syntax:
font-style: normal|italic|oblique|initial|inherit;
Font Weights:
The font-weight property is used to specify the degree of boldness, as in [font-weight: bold;]
Besides bold, the values normal, bolder, and lighter can be specified. Specific numbers also can
be given in multiples of 100 from 100 to 900, where 400 is the same as normal and 700 is the same
as bold.
41 | P a g e VSISCM
Font Shorthands:
If more than one font property must be specified, the values can be stated in a list as the value of
the font property. The order in which the property values are given in a font value list is Important.
The order must be as follows: The font names must be last, the font size must be second to last,
and the font style, font variant, and font weight, when they are included, can be in any order but
must precede the font size and font names. [font: bold 14pt 'Times New Roman';]
<html>
<head>
<title>Font Properties</title>
<style type = "text/css">
p.one
{
font-family: 'lucida calligraphy';
font-weight:bold;
font-size:75pt;
color purple;
}h
l.two
{
font-family: 'cambria';
color violet;
font-style:italics;
}
p. three
{
font: small-caps italic bold 50pt 'times new roman'
}
</style>
</head>
<body>
42 | P a g e VSISCM
Text Decoration:
The text-decoration property is used to specify some special features of text The available
values are line-through, over line, underline, and none, which is the default.
<html>
<head>
<title>Text Decoration</title>
<style type = "text/css^
hl.one
{text-decoration: line-through;}
hl.two
(text-decoration: overline;}
hl.three
{text-decoration: underline;}
</style>
</head>
<body>
<h 1 class = “one">Puneeth Rajkumar</h 1 > <p>[This is line-through]</p><br/>
<hl class = "two’’>Puneeth Rajkumar</hl> <p>(This is overline]</p><br/>
<hl class = "three">Puneeth Rajkumar</hlxp>[This is underline]</p><br/>
</body>
</html>
43 | P a g e VSISCM
LIST PROPERTIES
Two presentation details of lists can be specified in XHTML documents: the shape of the bullets
that precede the items in an unordcred list and the sequencing values that precede the items in an
ordered list The liststyle-type property is used to specify both of these.
The list-style-type property of an unordered list can be set to disc, circle, square, or none.
<html>
<head>
<tit!e>CSS Bullets</title>
<style type = "text/css">
li.one {list-style-type:disc}
li.two(list-style-type:square}
li.three{list-style-type:circle}
</style>
</head>
<body>
<h3>South Indian Kings</h3>
<ul>
<li class = "one">Puneeth Rajkumar</li>
<11 class = "two"> Mahesh Babu</li>
<li class = "three"<Suriya</li>
44 | P a g e VSISCM
</ul>
</body>
</html>
COLOR
Color Groups:
Three levels of collections of colours might be used by an XHTML document. The smallest
useful set of colours includes only those that have standard names and are guaranteed to be
correctly displayable by all browsers on all color monitors. This collection of 17 colours is
called the named colours.
45 | P a g e VSISCM
46 | P a g e VSISCM
Color Properties:
The color property is used to specify the foreground color of XHTML elements.
<html>
<head>
<title>Colours</title>
<style type = ”text/css">
p.one
{color: pink;}
p.two
{color: # 9900FF;}
p.three
{background-color:#99FF00;}
</style>
</head>
<body>
<p class = "one">Puneeth Rajkumar</p>
<p class = ”two">Puneeth Rajkumar</p>
<p class = "three">Puneeth Rajkumar</p>
</body></html>
Alignment of text
* The text-indent property can be used to indent the first line of a paragraph. This property takes
either a length or a percentage value. The text-align property, for which the possible keyword
valuesare left, center, right, and justify, is used to arrange text horizontally.
■ The float property is used to specify that text should flow around some element, often an image
or a table. The possible values for float are left, right, and none, which is the default.
47 | P a g e VSISCM
<html>
<head>
<title>Text Align ment</title>
<style type = "text/css">
hl.one
{text-align: center)
p.two
{text-indent: 0.5in; text-align: justify;}
img{float: right)
</style>
</head>
<body>
<hl class = "one"> Kannadada Kotyadhipathi</hl>
<p>
<img src = "kk.jpg" alt="error"/>
</p>
<p class = "two">Kannadada Kotyadhipathi is a Kannada primetime quiz show hosted by
the power star of Kannada cinema Mr. Puneet Rajkumar. This is the biggest game show ever
on Kannada Television. This show will be aired on Suvama TV. This show gives the common
man an opportunity to win Rs 1 crore. Kannadada Kotyadipathi is a Kannada primetime
quiz and human drama show hosted by matinee idol Puneeth Rajkumar on Suvarna TV.
Contestants participate in a game that allows them to win up to Rs. 1 crore. Short-listed
contestants play a ‘Fastest Finger First’ round to make it to the main game. From there on,
they play rounds with increasing levels of difficulty, and winning higher amounts of money,
culminating in the Rs. 1 crore prize. Contestants can stop at any time having viewed the next
question. Or they can avail of a 'Lifeline' and play on. Welcome to the world of high stakes
chills and thrills! Welcome to the world of the crorepati!</p>
</body>
</html>
48 | P a g e VSISCM
Borders:
Border-style
It can be dotted, dashed, double
► Border-top-style
► Border-bottom-style
► Border-left-style
► Border-right-style
49 | P a g e VSISCM
Border-width
It can be thin, medium, thick or any length value
► Border-top-width
► Border-bottom-width
► Border-left-width
► Border-right-width
Border-color
► Border-top-color
► Border-bottom-color
► Border-left-color
► Border-right-color
<html>
<head>
<title> Table with border effects </title>
<style type = "text/css">
table
{
border-width:thick;
border-top-color:red;
border-left-color:orange;
border-bottom-color: violet;
border-right-colorgreen;
border-bottom-style:d ouble;
border-right- style:dotted;
}
</style>
</head>
50 | P a g e VSISCM
<body>
<table border = "border">
<caption>PARAMATHMA </caption>
<tr>
<td> Puneeth Rajkumar </td>
<td> <img src = “puneeth.jpg" alt = "cant display"/></td>
</tr></table>
</body></html>
<html>
<head>
<title> Margins and Padding </title>
<style type = "text/css">
p.one
{
marginzO.lin;
padding:0.5in;
background-color:# FF33FF;
border-style:dotted;
51 | P a g e VSISCM
}
p.two
{
margin:0.5in;
padding:0.1in;
background-color:#00FF33;
border-sty le:dashed;
}
p.three
margin:0.3in;
background-color:#FFFFOO;
}
p.four
{
padding:0.3in;
background-color:# FF9900;
}
</style>
</head>
<body>
<p class = "one"> Puneeth Rajkumar is the Power Star of Sandalwood<br/>
[margin=0.1in, padding=0.5in]</p>
<p class = "two”> Puneeth Rajkumar is the Power Star of Sandalwood<br/>
[margin=0.5in, padding=0.1in]</p>
<p class = "three"> Puneeth Rajkumar is the Power Star ofSandalwood<br/>
[margin=0.3in, no padding, no border]</p>
<p class = "four"> Puneeth Rajkumar is the Power Star of Sandal wood <br/>
[no margin, padding=03in, no border]</p>
</body>
</html>
52 | P a g e VSISCM
BACKGROUND IMAGES
The background-image property is used to place an image in the background of an element.
<html>
<head>
<title>Background Image</title>
<style type = "text/css">
body {background-image:url(bg3.jpg);}
p{text-align: justify; color:white;font-size:25pt;}
</style>
</head>
<body>
<p >Kannadada Kotyadhipathi is a Kannada primetime quiz show hosted by the power star
of Kannada cinema Mr. Puneet Rajkumar. This is the biggest game show ever on Kannada
Television. This show will be aired on Suvarna TV. This show gives the common man an
opportunity to win Rs 1 crore. Kannadada Kotyadipathi is a Kannada primetime quiz and
human drama show hosted by matinee idol Puneeth Rajkumaron Suvarna TV. Contestants
participate in a game that allows them to win up to Rs. 1 crore. Short-listed contestants play
a 'Fastest Finger First* round to make it to the main game. From there on, they play rounds
with increasing levels of difficulty, and winning higher amounts of money, culminating in the
Rs. 1 crore prize. Contestants can stop at any time having viewed the next question. Or they
53 | P a g e VSISCM
can avail of a Lifeline' and play on.Welcome to the world of high stakes chills and thrills!
Welcome to the world of the crorepati!</p>
</body></html>
<html>
<head> <title>span</title>
<style type = "text/css">
.spanviolet {font-size:25pt;font-family:'lucida calligraphy';color:violet;}
</style>
</head>
<body>
<p >Kannadada Kotyadhipathi is a Kannada primetime quiz show hosted by <span class =
"spanviolet“>Puneeth Rajkumar </span>, the power star of Kannada cinema </p>
</body>
</html>
54 | P a g e VSISCM
CONFLICT RESOLUTION
Sometimes on a web page, there can be two different values for the same property on the
same element leading to conflict.
h3 {color: blue;}
body h3 {colon red;)
The browser has to resolve this conflict.
There can be one or more type of conflict: i.e. when style sheets at 2 or more levels specify
different value for same property on some element.
This conflict is resolved by providing priority to the different levels of style sheets.
The inline level gets the highest priority over the document level.
The document level gets the higher priority over the external level
But the browser must be able to resolve the conflict in the first example using same
technique.
There can be several different origins of the specification of property values.
One of the value may come from a style sheet created by the author or it can be specified
by the user using the options provided by the browser.
The property values with different origin have different precedence.
The precedence can also be set for a property by marking it as important.
p.special {font-style: italic {important; font-size: 14}
This means that font-style:italic is important [this is known as weight of specification]
The process of conflict resolution is a multi-stage sorting process.
The first step is to gather information about levels of style sheet
Next all the origins and weights are sorted. The following rules are considered:
1. Important declarations with user origin
2. Important declarations with author origin
3. Normal declarations with author origin
4. Normal declarations with user origin
5. Any declarations with browser (or other user agent) origin
■ If there are other conflicts even after sorting, the next step is sorting by specificity. Rules
are:
55 | P a g e VSISCM
1. id selectors
2. Class and pseudo class selectors
3. Contextual selectors (more element type names means that they are more specific)
4. Universal selectors
■ If there still conflicts, they are resolved by giving precedence to most recently seen
specification.
56 | P a g e VSISCM
UNIT-3
JAVASCRIPT
OVERVIEW OF JAVASCRIPT
ORIGINS
JavaScript, which was developed by Netscape, was originally named Mocha but soon
was renamed LiveScript.
In late 1995 LiveScript became a joint venture of Netscape and Sun Microsystems, and
its name again was changed, this time to JavaScript.
A language standard for JavaScript was developed in the late 1990s by the European
Computer Manufacturers Association (ECMAJas ECMA-262.
The official name of the standard language is ECMAScripL
JavaScript can be divided into three parts: the core, client side, and server side.
o The core is the heart of the language, including its operators, expressions,
statements, and subprograms.
Client-side JavaScript is a collection of objects that support the control of a browser and
interactions with users.
Server-side JavaScript is a collection of objects that make the language useful on a Web
server.
JAVA VS JAVASCRIPT
1) Execution Environment
First difference between Java and JavaScript is that Java is compiled + interpreted language, Java
code is fist compiled into class files containing byte code and than executed by JVM, on the other
hand JavaScript code is directly executed by browser. One more difference which comes form this
fact is that, Java is run inside JVM and needs JDK or JRE for running, on there other hand
57 | P a g e VSISCM
JavaScript runs inside browser and almost every modern browser supports JavaScript.
Another key difference between JavaScript and Java is that, JavaScript is a dynamic typed
language, while Java is a statically typed language. Which means, variables are declared with type
at compile time, and can only accept values permitted for that type, other hand variables are
declared using vary keyword in JavaScript, and can accept different kinds of value
e.g. String, numeric and boolean etc. When one variable or value is compared to other using ==
operator, JavaScript performs type coercion. Though it also provides === operator to perform strict
equality check, which checks for type as well.
3) Support of Closures
JavaScript supports closures, in form of anonymous function. In simple words, you can pass a
function as an argument to another function. Java doesn't treat method as first class citizen and
only way to simulate closure is by using anonymous class. By the way Java 8 has brought real
closure support in Java in form of lambda expression and this has made things much easier. It's
very easy to write expressive code without much clutter in Java 8.
4) OOP
Java is an Object Oriented Programming language, and though JavaScript also supports class and
object, it's more like an object oriented scripting language. It's much easier to structure code of
large enterprise application in Java then JavaScript. Java provides packages to group related class
together, provides much better deployment control using JAR, WAR and EAR as well.
58 | P a g e VSISCM
implementation of JavaScript. This was really bad until jQuery comes. Its a JavaScript library
which helps to free web developers from this browser compatibility issues. This is why I prefer to
write code using jQuery rather than using plain old JavaScript code, even if its as simple as
calling getElementById() or getElementByName() methods to retrieve DOM elements.
7) Constructors
Java has concept of constructors, which has some special properties e.g. constructor chaining and
ensuring that super class constructor runs before sub class, on the other hand JavaScript
constructors are just another function. There is no special rules for constructors in JavaScript e.g.
they cannot have return type or their name must be same as class.
8) NullPointerException
JavaScript is much more forgiving than Java, you don't have NullPointerException in JavaScript,
your variable can accept different kinds of data because of JavaScript is dynamically typed
language.
9) Applicability
Last but not the least, JavaScript has it's own space, sitting cozy along with HTML and CSS in
Web development, while Java is everywhere. Though both has good number of open source
libraries to kick start development, but jQuery has certainly brings JavaScript on fore front.
59 | P a g e VSISCM
USES OF JAVASCRIPT
The JavaScript was initially introduced to provide programming capability at both the
server and client ends of web connection
JavaScript therefore is implemented at 2 ends:
1. Client end
2. Server end
The client side JavaScript is embedded in XHTML documents and is interpreted by the
browser
It also provides some means of computation, which serves as an alternative for some tasks
done at the server side
Interactions with users through form elements, such as buttons and menus, can be
conveniently described in JavaScript. Because button clicks and mouse movements are
easily detected with JavaScript they can be used to trigger computations and provide
feedback to the user.
For example, when a user moves the mouse cursor from a text box. JavaScript can detect
that movement and check the appropriateness of the text box's value (which presumably
was just filled by the user).
Even without forms, user interactions are both possible and simple to program in
JavaScript. These interactions, which take place in dialog windows, include getting input
from the user and allowing the user to make choices through buttons. It is also easy to
generate new content in the browser display dynamically.
This transfer of task ensures that the server is not overloaded and performs only required
task
But client side JavaScript cannot replace serves side JavaScript; because server side
software supports file operations, database access, security, networking etc
JavaScript is also used as an alternative to java applets.
Programming in JavaScript is much simpler than compared to java
JavaScript support DOM [Document Object Model] which enables JavaScript to access
and modify CSS properties and content of any element of a displayed XHTML document
60 | P a g e VSISCM
JAVASCRIPT OBJECTS
In JavaScript, objects are collections of properties, which correspond to the members of
classes in Java and C++.
Each property is either a data property or a function or method property.
Data properties appear in two categories: primitive values and references to other objects.
JavaScript uses non-object types for some of its simplest types; these non-object types are
called primitives.
Primitives are used because they often can be implemented directly in hardware, resulting
in faster operations on their values.
All objects in a JavaScript program are indirectly accessed through variables.
All primitive values in JavaScript are accessed directly—these are like the scalar types in
Java and C++.
These are often called value types.
The properties of an object are referenced by attaching the name of the property to the
variable that references the object.
A JavaScript object appears, both internally and externally, as a list of property-value
pairs.
The properties are names; the values are data values or functions.
All functions are objects and are referenced through variables.
The collection of properties of a JavaScript object is dynamic: Properties can be added
or deleted at any time.
61 | P a g e VSISCM
In addition, JavaScript has a large collection of predefined words, including alert, open,
java, and self.
JavaScript has two forms of comments, both of which are used in other languages. First,
whenever two adjacent slashes (//) appear on a line, the rest of the line is considered a
comment. Second, /* may be used to introduce a comment, and */ to terminate it, in both
single- and multiple-line comments.
The XHTML comment used to hide JavaScript uses the normal beginning syntax, <!--.
The following XHTML comment form hides the enclosed script from browsers that do not
have
JavaScript interpreters, but makes it visible to browsers that do support JavaScript:
62 | P a g e VSISCM
The use of semicolons in JavaScript is unusual. The JavaScript interpreter tries to make
semicolons unnecessary, but it does not always work.
When the end of a line coincides with what could be the end of a statement, the interpreter
effectively inserts a semicolon there. But this can lead to problems. For example,
63 | P a g e VSISCM
64 | P a g e VSISCM
■ The only value of type Null is the reserved word null, which indicates no value.
■ The only value of type Undefined is undefined.
■ The only values of type Boolean are true and false.
DECLARING VARIABLES
A variable can be declared either by assigning it a value, in which case the interpreter
implicitly declares it to be a variable, or by listing it in a declaration statement that begins with
the reserved word var. Initial values can be included in a var declaration, as with some of the
variables in the following declaration:
var counter,
index,
pi - 3.14159265, quarterback
■ ’Elway”,atop_flag
■ true;
A variable that has been declared but not assigned a value, has the value undefined.
NUMERIC OPERATORS
■ JavaScript has the typical collection of numeric operators: the binary operators + for addition, -
for subtraction,* for multiplication, / for division, and % for modulus.
• The unary operators are plus (+), negate (-), decrement (--), and increment (++). The increment
and decrement operators can be either prefix or postfix.
■ For example, if the variable a has the value 7, the value of the following expression is 24:
(■Ha) *3
■ But the value of the following expression is 21:
(a++) *3
■ In both cases, a is set to 8.
■ But the value of the following expression is 21:
(a++) * 3
65 | P a g e VSISCM
66 | P a g e VSISCM
PROPERTY : Meaning
MAX. VALUE : Largest representable number
MIN. VALUE : Smallest representable number
NaN : Not a number
POSITIVE-INFINITY : Special value to represent infinity
NEGATIVE-INFINITY : Special value to represent negative infinity
PI : The value of π
The toString method converts the number through which it is called to a string. Example:
var price = 427,
str_price;
Btr_price = price.toString();
str_price = price. toString() ;
67 | P a g e VSISCM
68 | P a g e VSISCM
ASSIGNMENT STATEMENTS
There is a simple assignment operator, denoted by =, and a host of compound assignment
operators, such as +=and For example, the statement a += 7; means the same as a = a + 7;
69 | P a g e VSISCM
Method Description
getTime() Returns the number of milliseconds since midnight Jan 1 1970, and a
specified date
70 | P a g e VSISCM
71 | P a g e VSISCM
The confirm method opens a dialog window in which the method displays its string
parameter, along with two buttons: OK and Cancel.confirm returns a Boolean value that
indicates the user’s button input: true for OK and false for Cancel.
This method is often used to offer the user the choice of continuing some process.
var question = confirm("Do you want to continue this download?");
After the user presses one of the buttons in the confirm dialog window, the script can test
the variable, question, and react accordingly.
The prompt method creates a dialog window that contains a text box used to collect a
string of input from the user, which prompt returns as its value.
CONTROL STATEMENTS
A compound Statement in JavaScript is a sequence of statements delimited by braces.
A control construct is a control statement together with the statement or compound
statement whose execution it controls.
CONTROL EXPRESSIONS
The result of evaluating a control expression is one of the Boolean values true and false.
If the value of a control expression is a string, it is interpreted as true unless it is either the
empty string (" ") or a zero string ("0").
If the value is a number, it is true unless it is zero (0). A relational expression has two
operands and one relational operator. Table 4.6 lists the relational operators.
72 | P a g e VSISCM
returning true
Not equal (!=) Returns true if the operands are not equal. var1 != 4
var2 != "3"
Strict equal (===) Returns true if the operands are equal and of the same type. 3 === var1
See also Object.is and sameness in JS.
Strict not Returns true if the operands are of the same type but not equal, var1 !== "3"
Greater than or Returns true if the left operand is greater than or equal to the var2 >= var1
Less than (<) Returns true if the left operand is less than the right operand. var1 < var2
"2" < 12
Less than or Returns true if the left operand is less than or equal to the right
equal (<=) operand.
JavaScript has operators for the AND, OR, and NOT Boolean operations. These are &&
(AND), | I (OR), and ! (NOT). Both && and | I are short-circuit operators.
SELECTION STATEMENTS
The selection statements (if-then and if-then-else) of JavaScript are similar to those of the common
programming languages. Either single statements or compound statements can be selected—for
example,
If (a > b)
document, .write <“a Is greater than b <br />”);
else {
a = b;
73 | P a g e VSISCM
74 | P a g e VSISCM
LOOP STATEMENTS:
The general form for while statement
document.write(
"Date: " + datestring + "<br />",
"Days " + day + "<br />•,
"Month: “ + month + "<br />*,
•Year: “ + year “ "<br />",
75 | P a g e VSISCM
76 | P a g e VSISCM
The variable my_object references the new object. Calls to constructors must include
parentheses, even if there are no parameters.
The properties of an object can be accessed with dot notation, in which the first word is the
object name and the second is the property name. Because properties are not variables, they
are never declared in javabcnpr, nowever, tne new operator creates a DianK ooject—tnat is,
one witn no properties.
The following statement creates an object that has no properties:
var my_object - new Object ();
In this case, the constructor called is that of Ob j ect, which endows the new object with no
properties, although it does have access to some inherited methods.
The variable my_object references the new object. Calls to constructors must include
parentheses, even if there are no parameters.
The properties of an object can be accessed with dot notation, in which the first word is the
object name and the second is the property name. Because properties are not variables, they
are never declared.
The number of members of a class in a typical object-oriented language is fixed at compile
time. Thenumber of properties in a JavaScript object is dynamic.
At any time during interpretation, properties can be added to or deleted from an object. A
property for an object is created by assigning a value to that property’s name. Consider the
following example:
var my car = {make: "Ford", model: "Contour SVT"};
Properties can be accessed in two ways.
var propl = my car.make;
var prop2 = my_car["make"];
the variables propl and prop2 both have the value "Ford".
A property can be deleted with delete, as in the following example:
delete my_car.model;
JavaScript has a loop statement, for-in, that is perfect for listing the properties of an object,
for (var prop in my_car>
document.write("Name: ", prop, Value: ",
my_car[prop], "<br />“);
77 | P a g e VSISCM
ARRAYS
Array OBJECT CREATION
The usual way to create any object is with the new operator and a call to a constructor. In the
case of arrays, the constructor is named Array:
var my_list = new Array(1, 2, "three", "four");
var your_list = new Array(100);
The second way to create an Array object is with a literal array value, which is a list of values
enclosed in brackets:
var my_list_2 = [1, 2, "three", "four"];
78 | P a g e VSISCM
79 | P a g e VSISCM
Array METHODS
Array objects have a collection of useful methods, most of which are described in this section.
The join method converts all of the elements of an array to strings and catenates them into a
single string. If no parameter is provided to join, the values in the new string are separated by
commas. If a string parameter is provided, it is used as the element separator.
The reverse method reverses the order of the elements of the Array object through which it is
called.
The sort method coerces the elements of the array to become strings if they are not already
strings and sorts them alphabetically
The concat method catenates its actual parameters to the end of the Array object on which it
is called.
When the toString method is called through an Array object, each of the elements of the object
is converted (if necessary) to a string. These strings are catenated, separated by commas. So,
for Array objects, the toString method behaves much like join.
The push, pop, unshift, and shift methods of Array allow the easy implementation of stacks
and queues in arrays. The pop and push methods respectively remove and add an element to
the high end of an array.
FUNDAMENTALS
A function definition consists of the function's header and a compound statement that
describes the actions of the function. This compound statement is called the body of the
function.
A function header consists of the reserved word function, the function’s name, and a
parenthesized list of parameters if there are any.
A return statement returns control from the function in which it appears to the function’s
caller.
A function body may include one or more return statements. If there are no return
statements in a function or if the specific return that is executed does not include an
expression, the value returned is undefined.
JavaScript functions are objects, so variables that reference them can be treated as are other
object references—they can be passed as parameters, be assigned to other variables, and
be the elements of an array. The following example is illustrative:
80 | P a g e VSISCM
LOCAL VARIABLES
• The scope of a variable is the range of statements over which it is visible.
• When JavaScript is embedded in an XHTML document, the scope of a variable is the range
of lines of the document over which the variable is visible.
• Variables that are implicitly declared have global scope—that is, they are visible in the entire
XHTML document
• It is usually best for variables that are used only within a function to have local scope, meaning
that they are visible and can be used only within the body of the function. Any variable
explicitly declared with var in the body of a function has local scope.
• If a variable that is defined both as a local variable and as a global variable appears in a
function, the local variable has precedence, effectively hiding the global variable with the
same name. This is the advantage of local variables.
PARAMETERS
The parameter values that appear in a call to a function are called actual parameters.
The parameter names that appear in the header of a function definition, which correspond
to the actual parameters in calls to the function, are called formal parameters.
JavaScript uses the pass-by-value parameter-passing method.
When a function is called, the values of the actual parameters specified in the call are, in
effect, copied into their corresponding formal parameters, which behave exactly like local
variables.
Because of JavaScript’s dynamic typing, there is no type checking of parameters. The
called function itself can check the types of parameters with the typeof operator.
81 | P a g e VSISCM
The number of parameters in a function call is not checked against the number of formal
parameters in the called function.
In the function, excess actual parameters that are passed are ignored; excess formal
parameters are set to undefined.
All parameters are communicated through a property array, arguments, that, like other
array objects, has a property named length.
By accessing arguments length, a function can determine the number of actual parameters
that were passed.
// params.js
// The params function and a test driver for it.
// This example illustrates a variable number of
// function parameters
// Function params
// Parameters: A variable number of parameters
II Returns: nothing
// Displays its parameters
function params(a, b) {
document.write("Function params was passed ”,
arguments.length, " parameter(s) <br />");
document.writef"Parameter values are: <br />");
for (var arg = 0; arg < arguments.length; arg++)
document.write(arguments(arg|, "<br />");
document.write("<br />");
}
// A test driver for function params
params("Mozart");
params("Mozart", "Beethoven");
params("Mozart", "Beethoven", "Tchaikowsky");
82 | P a g e VSISCM
CONSTRUCTORS
JavaScript constructors are special methods that create and initialize the properties of newly
created objects.
Every new expression must include a call to a constructor whose name is the same as that of
the object being created.
Constructors are actually called by the new operator, which immediately precedes them in
the new expression.
Obviously, a constructor must be able to reference the object on which it is to operate.
JavaScript has a predefined reference variable for this purpose, named this.
When the constructor is called, this is a reference to the newly created object. The this
variable is used to construct and initialize the properties of the object.
For example, the constructor
function car(new_make, new_nodel, nev_year) {
this.make “ new_make;
this. model - new_model;
this.year ■ new_year;
}
could be used as in the following statement:
my_car = new car("Ford", "Contour SVT", "2000");
83 | P a g e VSISCM
ANCHORS
A pattern is tied to a string position with an anchor. A pattern can be specified to match
only at the beginning of the string by preceding it with a circumflex (') anchor.
For example, the following pattern matches "pearls are pretty" but does not match "My
pearls are pretty":
/^pearl/
A pattern can be specified to match at the end of a string only by following the pattern
with a dollar sign anchor. For example, the following pattern matches "I like gold" but
does not match "golden":
84 | P a g e VSISCM
/gold$/
Anchor characters are like boundary-named patterns: They do not match specific
characters in the string; rather, they match positions before, between, or after characters.
PATTERN MODIFIERS
• The modifiers are specified as letters just after the right delimiter of the pattern.
• The i modifier makes the letters in the pattern match either uppercase or lowercase letters
in the string.
• For example, the pattern /Apple/i matches ‘APPLE’, 'apple', 'APPle', and any other
combination of uppercase and lowercase spellings of the word "apple."
• The x modifier allows white space to appear in the pattern.
ERRORS IN SCRIPTS
The JavaScript interpreter is c from debugging a program in the JavaScript interpreter are
script error causes the browse diagnostic message, you must apable of detecting vari
more typical program found while the browse r not to display the doc simply examine the code
//debugdemo.
// An example to illustrate debugging help
var row;
row = 0;
while(row != 4 {
document.write("row is”,row “<br />”);
row++;
}
85 | P a g e VSISCM
Unit - 4
Java Script and HTML Documents
86 | P a g e VSISCM
• With the DOM. users can write code in programming languages to create documents, move
around in their structures, and change, add, or delete elements and their content.
• Documents in the DOM have a treelike structure, but there can be more than one tree in a
document
• Because the DOM is an abstract interface, it does not dictate that documents be implemented
as trees or collections of trees.
• <html xmlns = “http://www.w3.org/1999/xhtml1”>
• <head> <title> A simple table </title>
• </head>
• <body>
• <table border = "border">
• <tr>
• <th> </th>
• <th> Apple </th>
• <th> Orange </th>
• </tr>
• <tr>
• <th> Breakfast </th>
• <td> 0 </td>
• <td> 1 </td>
• </tr>
• </table>
• </body>
• </html>
87 | P a g e VSISCM
The DOM address of the button in this example, using the forms and elements arrays, is as follows:
var dom — document.forms[0].elements[0];
The problem with this approach to element addressing is that the DOM address is defined by
address elements that could change—namely, the forms and elements arrays.
88 | P a g e VSISCM
89 | P a g e VSISCM
if (dom.vehicles!index].checked)
numChecked++;
Radio buttons can be addressed and handled exactly as are the checkboxes in the foregoing code.
90 | P a g e VSISCM
Attribute Description
onblur Executed the script when form element loses the focus.
onchange Executed the script when the value of the element is changed.
oninput Executed the script when the user enters input to the element.
oninvalid Executed the script when the element does not satisfy its predefined constraints.
onreset Triggers the event when user reset the form element values.
onsearch Triggers the event when a search field receives some input.
onselect Triggers the event when the user has selected some text.
Attribute Description
keydown Triggers the event when the user presses down a key on the keyboard.
keypress Trigger the event when the user presses the key which displays some character.
91 | P a g e VSISCM
keyup Trigger the event when the user releases the currently pressed key.
Attribute Description
click Trigger the event when the mouse clicks on the element.
dblclick Trigger the event when mouse double-click occurs on the element.
mousedown Trigger the event when the mouse button is pressed on the element.
mousemove Trigger the event when the mouse pointer moves over the element.
mouseout Trigger the event when the mouse moves outside the element.
mouseover Trigger the event when the mouse moves onto the element.
onwheel Trigger the event when the mouse wheel rolls up or down on the element
92 | P a g e VSISCM
93 | P a g e VSISCM
First, it determines whether the user typed the initial password (in the first input box) by testing
the value of the element against the empty string. If no password has been typed into the first
field, the function calls alert to produce an error message and returns false.
The second test determines whether the two typed passwords are the same. If they are
different, once again the function calls alert to generate an error message and returns
false.
94 | P a g e VSISCM
EVENT PROPAGATION:
• A browser which understands DOM, on receiving the XHTML document from the server,
creates a tree known as document tree.
• The tree constructed consists of elements of the document except the HTML
• The root of the document tree is document object itself
• The other elements will form the node of the tree
95 | P a g e VSISCM
• In case of DOM2, the node which generates an event is known as target node
• Once the event is generated, it starts the propagation from root node
• During the propagation, if there are any event handlers on any node and if it is enabled then
event handler is executed.
• Once the event is generated, it starts the propagation from root node
• During the propagation, if there are any event handlers on any node and if it is enabled then
event handler is executed
• The event further propagates and reaches the target node.
• When the event handler reaches the target node, the event handler gets executed
• After this execution, the event is again re-propagated in backward direction
• During this propagation, if there are any event handlers which are enabled, will be executed.
• The propagation of the even from the root node towards the leaf node or the target node is
known as capturing phase.
• The execution of the event handler on the target node is known as execution phase.
• This phase is similar to event handling mechanism in DOM - 0
• The propagation of the event from the leaf or from the target node is known as bubbling
phase
• All events cannot be bubbled for ex: load and unload event
• If user wants to stop the propagation of an event, then stop propagation has to be executed.
What is DOM?
DOM traversing
DOM manipulating
What is DOM?
The Document Object Model (DOM) is a programming API for HTML and XML. API
specification defined by the World Wide Web Consortium (W3C). DOM represents how to write
HTML and XML in tree like structure also traversing and manipulating structure in order to create
dynamic web application.
96 | P a g e VSISCM
Traversing and manipulating DOM structure we relay on client side scripting language like
JavaScript. Here we can add, modify, delete and attach events in DOM structure.
DOM traversing
DOM traversing, which means “move through”, are used to “find” (or select) HTML elements
based on their relation to other elements. Here traversing happen in both direction top to bottom
or bottom to top. Start with one selection and move through that selection until you reach the
elements you desire.
97 | P a g e VSISCM
**************************************************************************
98 | P a g e VSISCM
UNIT 5
DYNAMIC DOCUMENTS WITH JAVASCRIPT
INTRODUCTION
• Informally, a dynamic XHTML document is an XHTML document that in some way, can be
changed while it is being displayed by a browser.
• Dynamic XHTM L is not a new markup language.
• It is a collection of technologies that allows dynamic changes to documents defined with
XHTML
• Specifically, a dynamic XHTML document is an XHTML document whose tag attributes, tag
contents, or element style properties can be changed by user interaction or the occurrence of
a browser event after the document has been, and is still being, displayed.
• Such changes can be made with an embedded script that accesses the elements of the
document as objects in the associated DOM structure.
POSITIONING ELEMENTS
• A Cascading Style Sheet - Positioning (CSS-P) is completely supported by IE8 and FX3.
• As it provides the means not only to position any element anywhere in the display of a
document, but also to move an element to a new position in the display dynamically, using
JavaScript to change the positioning style properties of the element.
• As These style properties, which are appropriately named left and top, dictate the distance
from the left and top of some reference point to where the element is to appear.
• Another style property, position, interacts with left and top to provide a higher level of control
of placement and movement of elements.
• The position property has three possible values: absolute, relative, and static.
ABSOLUTE POSITIONING
• The absolute value is specified for position when the element is to be placed at a specific place
in the document display without regard to the positions of other elements.
• One use of absolute positioning is to superimpose special text over a paragraph of ordinary
text to create an effect similar to a watermark on paper.
99 | P a g e VSISCM
RELATIVE POSITIONING
• An element that has the position property set to relative, but does not specify top and
left property values, is placed in the document as if the position attribute were not set at all.
• However, such an element can be moved later.
STATIC POSITIONING
The default value for the position property is static. A statically positioned element is placed in
the document as if it had the position value of relative but no values for top or left were given.
The difference is that a statically positioned element cannot have its top or left properties initially
set or changed later. Therefore, a statically placed element cannot be displaced from its normal
position and cannot be moved from that position later.
MOVING ELEMENTS
Moving an element is simple:
• Changing the top or left property values causes the element to move on the display.
• If its position is set to absolute, the element moves to the new values of top and left; its
position is set to relative, it moves from its original position by distances given by the
new values of top and left.
ELEMENT VISIBILITY
• Document elements can be specified to be visible or hidden with the value of their
visibility property.
• The two possible values for visibility are, quite naturally, visible and hidden.
• The appearance or disappearance of an element can be controlled by the user through a
widget.
• //showHide.html
• <html>
• <head>
100 | P a g e VSISCM
• <title>Visibi li ty Control</title>
• <script type="text/javascript" src="showHide.js">
• </script>
• </head>
• <body>
• <form action="">
• <div id="rnsit" style="position:relative; visibility: visible;">
• <img src = "CLASS PHOTO.jpg" alt = "RNSIT ISE 2009-2013" />
• </div>
• <p><br><input type="button" value="Toggle Rnsit" ondick = "fliplmagO" /></p>
• </form>
• </body>
• </html>
• //showHide.js
• function fliplmag( ) {
• dom=document.getElementById("rnsit").style;
• if(dom.visibility == "visible")
• dom.visibility = "hidden";
• else
• dom.visibility = "visible";
• }
101 | P a g e VSISCM
CHANGING COLORS
• Dynamic changes to colors are relatively simple.
• In the next example, the user is presented with two text boxes into which color specifications
can be typed—one for the document background color and one for the foreground color.
• The colors can be specified in any of the three ways that color properties can be given in
CSS.
• A JavaScript function that is called whenever one of the text boxes is changed makes the
change in the document’s appropriate color property: back-groundColor or color.
• The first of the two parameters to the function specifies whether the new color is for the
background or foreground; the second specifies the new color.
• The new color is the value property of the text box that was changed by the user,
102 | P a g e VSISCM
• <html><title>Dynamic Colors</title>
• <scripttype="text/javascript" src = "dynColors.js">
• </script>
• </head>
• <body>
• <form action="">
• <p>
• <label>Background Color: <input type="text" name="bg" size = "20"
onchange="setColorCbg', this.value)" /></label>
• <label>Foreground Color: cinput type="text" name="fg" size = "20"
onchange="setColor('fg’, this.value)" /> </label>
• <br/>/p>
• </form>
• </body>
• </html>
• //dyn Color. js
• function setColorf where, newColor)
• {
• if( where == "bg")
• document.body.style.backgroundColor = newColor;
• else
• document.body.style.color = newColor;
103 | P a g e VSISCM
DYNAMIC CONTENT
• We now develop an example that illustrates one use of dynamic content.
• Assistance to a browser user filling out a form can be provided with an associated text area,
often called a help box.
• The content of the help box can change, depending on the placement of the mouse cursor.
• When the cursor is placed over a particular input field, the help box can display advice on how
the field is to be filled in.
• When the cursor is moved away from an input field, the help box content can be changed to
simply indicate that assistance is available.
• In the next example, an array of messages that can be displayed in the help box is defined in
JavaScript.
• When the mouse cursor is placed over an input field, the mouseover event is used to call a
handler function that changes the help box content to the appropriate value
• The appropriate value is specified with a parameter sent to the handler function.
• The mouseout event is used to trigger the change of the content of the help box back to the
"standard" value.
• //dynValue.html
• <html>
• <head>
• <title> Dynamic Values</title>
• <script type = "text/javascript" src = ”dynValue.js">
• </script>
• </hcad>
• <body>
• <form action="">
• <p style = "font-weight: bold">
• <span style = "font-style: italic">
• Customer Information
• </span>
104 | P a g e VSISCM
• <br>
• <label>Name:
• <input type="text" onmouseover="messages(0)" onmouseout=”messages(4)" />
• </label>
• <br>
• <label>Email:
• <inputtype="text" onmouseover="messages(1)”onmouseout="messages(4)" />
• </label>
• <brxbr><br>
• <span style = "font-style:italic">
• To create an account, provide the following information:
• </span>
• <brxbr>
• <label>User ID:
• <inputtype="text" onmouseover=“messages(2)" onmouseout=”messages(4J" />
• </label>
• <br>
• <label>Password:
• <inputtype="text" onmouseover="messages(3)" onmouseout="messages(4)" />
• </label>
• <br>
• <textarea id="adviceBox" rows="3" cols="50" style=”position:absolute; !eft:250px;
top:0px">
• This box provides advice on filling out the form on this page. Put the mouse cursor over
any input field to get advice.
• </textarea>
• <brxbr>
• <input type="submit" value= "Submit" />
• <input type="reset" value="Reset" />
• </p>
• </form>
105 | P a g e VSISCM
• </body>
• </html>
• //dynValue.js
• var helpers = ("Your name must be in the form: \n first name, middle initial., last name",
• "Your email address must have the form: \ user@domain",
• "Your user ID must have at least six characters and it must include one digit",
• "This box provides advice on filling out the form on this page. Put the mouse cursor over
any input field to get advice"]
• function messages(adviceNumber)
• {
• document.getElementByld("adviceBox").value=helpers[ad viceNumber];
• }
106 | P a g e VSISCM
STACKING ELEMENTS
• The top and left properties allow the placement of an element anywhere in the two dimensions
of the display of a document.
• Although the display is restricted to two physical dimensions, the effect of a third dimension
is possible through the simple concept of stacked elements, such as that used to stack windows
in graphical user interfaces.
• Although multiple elements can occupy the same space in the document, one is considered to
be on top and is displayed.
• The top element hides the parts of the lower elements on which it is superimposed.
• The placement of elements in this third dimension is controlled by the z-index attribute of the
element.
• An element whose z-index is greater than that of an element in the same space will be
displayed over the other element, effectively hiding the element with the smaller z-index
value.
• The JavaScript style property associated with the z-index attribute is zIndex,
107 | P a g e VSISCM
• //stackhtml
• <html >
• <head><title>Stacking Paragraphs</tide>
• <style type="text/css">
• .para1
• {
• border: solid thick #C0C0C0;
• padding: 1 in;
• width: 180px;
• backgrou nd -color: #0000 DO;
• colorwhite;
• position:absolute;
• top:70px;
• left:4in;
• z-index: 1;
• }
• .para2
• {
• border: solid thick #808000;
• padding: lin;
• width: 180px;
• background -color:red;
• colorwhite;
• position:absolute;
• top:105px;
• left:5in;
• z-index:2;
• }
• .para 3
• {
• border: solid thick #00ffff;
108 | P a g e VSISCM
• padding: lin;
• width: 180px;
• background-colongreen;
• color: white;
• position:absolute;
• top:140px;
• left:6in;
• z-index:3;
• }
• .display
• {
• font-size:25pt;
• colonblue;
• text-align:center;
• }
• p:hover{background-color:rgb(250,200,150);font-size:25px;color:white;};
• </style>
• <script type="text/javascript">
• var stackl="stackl";
• function move(curStack)
• {var oldStack=document.getElementById(stackl).style;
• oldStack.zIndex=”0";
• var newStack=document.getElementById(curStack).style;
• newStack.zIndex="10";
• stackl=document.getElcmentById(curStack).id;
• }
• </script>
• </head>
• <body>
• <h2 class=”display">Stacking of Paragraphs on top of each other</h2>
• <p class="paral" id="stackl" onmouseover="move(’stackr)">
109 | P a g e VSISCM
• Dr R N Shetty
• </p>
• <p class="para2" id="stack2" onmouseover="move('stack2‘)">
• Dr H N ShivShankar
• </p>
• <p class="para3" id="stack3" onmouseover="move(’stack3’)">
• Dr M K Venkatesha
• </p>
• </body>
• </html>
110 | P a g e VSISCM
111 | P a g e VSISCM
• //anywhere.html
• <html>
• <head>
• <title>Sense events anywhere</title>
• <script type= "text/javascript" >
• function displaylt(evt){
• vardom=documentgetElementByld("message");
• dom.style.left=(evt.clientX -130) + "px";
• dom.style.top=(evt.clientY - 25 ) + "px";
• dom.style.visibility= "visible";
• }
• function hidelt()
• {
• document.getElementByld("message").style.visibility="hidden";
• } </script>
• </head>
• <body onmousedown="displaylt(event);" onmouseup="hidelt();">
• <P>
• <span id="message”
• style = "coloured; visibility:hidden; position:relative; font-size:20pt; font-weight:bold;">
• Please Don’t Click Here..!!
• </span>
• <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br>< br> <br> <b rx br>< br> <br>
<br ><b r>< br> <br> <b rxb r>< br>< br> <br> <br>< br>< br> <br> <br>< br>< br>
<br><b r>< brx br> <br><b r>< br> <br> <b r>< br>< br> <br> <br ><b r>< br> <br>
<br><b r>< br>< br> <br> <b r><br><br>< br>< br> <br ><br >< br>< br> <br><br>
• < br>
• </p>
• </body>
• </html>
112 | P a g e VSISCM
113 | P a g e VSISCM
INTRODUCTION TO XML
SYNTAX OF XML
• XML imposes two distinct levels of syntax:
• There is a general low level syntax that is appreciable on all XML documents
• The other syntactic level is specified by DTD (Document Type Definition) or XML schemas.
• The DTDs and XML schemas specify a set of tag and attribute that can appear in a particular
document or collection of documents.
• They also specify the order of occurrence in the document.
• The XML documents consists of data elements which form the statements of XML document
• The XML document might also consists of markup declaration, which act as instructions to
the XML parser
114 | P a g e VSISCM
• All XML documents begin with an XML declaration. This declaration identifies that the
document is a XML document and also specifies version number of XML standard.
• It also specifies encoding standard.
• <?xml version = "1.0" encoding = "utf-8"?>
• Comments in XML is similar to HTML
• XML names are used to name elements and attributes.
• XML names are case-sensitive.
• There is no limitation on the length of the names.
• All XML document contains a single root element whose opening tag appears on first line of
the code
• All other tags must be nested inside the root element
• As in case of XHTML, XML tags can also have attributes
• The values for the attributes must be in single or double quotation.
115 | P a g e VSISCM
XML Declaration
• The XML declaration is a piece of markup (which may span multiple lines of a file) that
identifies this as an XML document. The declaration also indicates whether the document can
be validated by referring to an external Document Type Definition (DTD). DTDs are the
subject of chapter 4; for now, just think of a DTD as a set of rules that describes the structure
of an XML document.
• XML is case-sensitive (more about this in the next subsection), so it's important that you use
lowercase for xml and version. The quotes around the value of the version attribute are
required, as are the? Characters. At the time of this writing, "1.0" is the only acceptable value
for the version attribute, but this is certain to change when a subsequent version of the XML
specification appears.
• The following declaration means that there is an external DTD on which this document
depends. See the next subsection for the DTD that this negative standalone value implies.
• <?xml version="1.0" standalone="no" ?>
• On the other hand, if your XML document has no associated DTD, the correct XML
declaration is:
• <?xml version="1.0" standalone="yes" ?>
116 | P a g e VSISCM
In this example, we are indicating that the DTD and the XML document reside in the same
directory (i.e., the ExternalDeclarations are contained in the file employees.dtd) and that the
root element is Employees:
In the next example, we use normal directory path syntax to indicate a different location for
the DTD.
117 | P a g e VSISCM
Document Body
• The document body, or instance, is the bulk of the information content of the document.
Whereas across multiple instances of a document of a given type (as identified by
the DOCTYPE) the XML prolog will remain constant, the document body changes with each
document instance (in general).
• Because the document type declaration specifies the root element, this must be the first
element the parser encounters. If any other element but the one identified by
the DOCTYPE line appears first, the document is immediately invalid.
DECLARING ELEMENTS
• DTD follows rules of context-free grammar for element declaration
• A DTD describes the syntactic structure of a particular set of documents
• Each element declaration in a DTD specifies the structure of one category of elements
• An element is a node in such a tree either a leaf node or an internal node
• A If element is leaf node, its syntactic description is its character pattern
• If the element is internal node, its syntactic description is a list of its child element
• The form of an element declaration for elements that contain elements is as follows:
118 | P a g e VSISCM
• In many cases, it is necessary to specify the number of times that a child element may appear.
• This can be done in a DTD declaration by adding a modifier to the child element
specification. These modifiers, described in Table 7.1, are borrowed from regular
expressions.
• Any child element specification can be followed by one of the modifiers.
XML attributes.
• Attributes are part of XML elements. An element can have multiple unique attributes.
• Attribute gives more information about XML elements. To be more precise, they define
properties of elements. An XML attribute is always a name-value pair.
Syntax
119 | P a g e VSISCM
....content..
< /element-name>
name = "value"
value has to be in double (" ") or single (' ') quotes. Here, attribute1 and attribute2 are unique
attribute labels.
Attributes are used to add a unique label to an element, place the label in a category, add a Boolean
flag, or otherwise associate it with some string of data. Following example demonstrates the use
of attributes −
<garden>
<plants category = "flowers" />
<plants category = "shrubs">
</plants>
</garden>
Attributes are used to distinguish among elements of the same name, when you do not want to
create a new element for every situation. Hence, the use of an attribute can add a little more detail
in differentiating two or more similar elements.
In the above example, we have categorized the plants by including attribute category and
assigning different values to each of the elements. Hence, we have two categories of plants,
one flowers and other shrubs. Thus, we have two plant elements with different attributes.
120 | P a g e VSISCM
You can also observe that we have declared this attribute at the beginning of XML.
Attribute Types
StringType It takes any literal string as a value. CDATA is a StringType. CDATA is character
data. This means, any string of non-markup characters is a legal part of the
attribute.
This is a more constrained type. The validity constraints noted in the grammar
are applied after the attribute value is normalized. The TokenizedType attributes
TokenizedType
are given as −
121 | P a g e VSISCM
This has a list of predefined values in its declaration. out of which, it must assign
one value. There are two types of enumerated attribute −
An attribute name must not appear more than once in the same start-tag or empty-element
tag.
122 | P a g e VSISCM
An attribute must be declared in the Document Type Definition (DTD) using an Attribute-
List Declaration.
Attribute values must not contain direct or indirect entity references to external entities.
The replacement text of any entity referred to directly or indirectly in an attribute value must
not contain a less than sign (<)
DECLARING ENTITIES
• Entities can be defined so that they can be referenced anywhere in the content of an XML
document, in which case they are called general entities. The predefined entities are all
general entities.
• Entities can also be defined so that they can be referenced only in DTDs, in which case
they are called parameter entities.
• The form of an entity declaration is <!ENTITY [%] entity_name "entity_yalue">
• When the optional percent sign (A) is present in an entity declaration, it specifies that the
entity is a parameter entity rather than a general entity.
• Example: <! ENTITY sbs "Santhosh B Suresh">
• When an entity is longer than a few words, its text is defined outside the DTD. In such
cases, the entity is called an external text entity. The form of the declaration of an external
text entity is <!ENTITY entity_name SYSTEM "file_location">
• Some XML parsers check documents that have DTDs in order to ensure that the
documents conform to the structure specified in the DTDs. These parsers are called
validating parsers.
• If an XML document specifies a DTD and is parsed by a validating XML parser, and the
parser determines that the document conforms to the DTD, the document is called valid.
• Handwritten XML documents often are not well formed, which means that they do not
follow XML’s syntactic rules.
• Any errors they contain are detected by all XML parsers, which must report them.
• XML parsers are not allowed to either repair or ignore errors.
123 | P a g e VSISCM
• Validating XML parsers detect and report all inconsistencies in documents relative to their
DTDs.
124 | P a g e VSISCM
• <VTU>
• <students>
• <USN> 1RN10CS090 </USN>
• <name> Santhosh B S</name>
• <college> RNSIT </college>
• <branch> CSE </branch>
• <year> 2010 </year>
• <email> santhosh. b.suresh@gmail.com </email>
• </students>
• <students>
• <USN> 1RN0IS016 </USN>
• <name> Divya K </name>
• <college> RNSIT </college>
• <branch> ISE </branch>
• <year> 2009 </year>
• <email> divya@gmail.com </email>
• </students>
• <students>
• <USN> 1RN0IS016 </USN>
• <name> Divya K </name>
• <college> RNSIT </college>
• <branch> ISE </branch>
• <year> 2009 </year>
• <email> divya@gmail.com </email>
• </students>
• </VTU>
NAMESPACES
• One problem with using different markup vocabularies in the same document is that
collisions between names that are defined in two or more of those tag sets could result
• An example of this situation is having a <table> tag for a category of furniture and a
<table> tag from
• XHTML for information tables.
• Clearly, software systems that process XML documents must be capable of unambiguously
recognizing the element names in those documents.
125 | P a g e VSISCM
• To deal with this problem, the W3C has developed a standard for XML namespaces (at
• http://www.w3.org/TR/REC-xml-names).
• An XML namespace is a collection of element and attribute names used in XML
documents. The name of a namespace usually has the form of a uniform resource
identifier (URI).
• A namespace for the elements and attributes of the hierarchy rooted at a particular element
is declared as the value of the attribute xmlns.
• The form of a namespace declaration for an element is
• <element_name xmlns [-.prefix] = URI>
• The square brackets indicate that what is within them is optional. The prefix, if included,
is the name that must be attached to the names in the declared namespace.
• If the prefix is not included, the namespace is the default for the document.
• A prefix is used for two reasons. First, most URls are too long to be typed on every
occurrence of every name from the namespace. Second, a UR1 includes characters that are
invalid in XML.
• Note that the element for which a namespace is declared is usually the root of a document.
• For ex: all XHTML documents in this notes declare the xmlns namespace on the root
element, html: <html xmlns = "http://www.w3.org/1999/xhtml">
• This declaration defines the default namespace for XHTML documents, which is
• http://www.w3.org/1999/xhtml.
• The next example declares two namespaces. The first is declared to be the default
namespace: the second defines the prefix, cap:
• <states>
• xmlns = "http://www.states-info.org/states"
• xmlns:cap - "http://www.states-info.org/state-capitals"
• </state>
• <name> South Dakota
• <population> 754844</population>
• <capital>
• <cap:name> Pierre </cap:name>
• <cap:population>12429 </cap:population>
126 | P a g e VSISCM
• </capital>
• </state>
• <!— More states —>
• </states>
XML SCHEMAS
• XML schemas is similar to DTD i.e. schemas are used to define the structure of the document
• DTDs had several disadvantages:
The syntax of the DTD was un-related to XML, therefore they cannot be analysed with an
XML processor
It was very difficult for the programmers to deal with 2 different types of syntaxes
DTDs does not support the datatype of content of the tag. All of them are specified as text
• Hence, schemas were introduced
SCHEMA FUNDAMENTALS
• Schemas can be considered as a class in object oriented programming
• A XML document that conforms to the standard or to the structure of the schema is similar
to an object
• The XML schemas have 2 primary purposes.
• They are used to specify the structure of its instance of XML document including which
• elements and attributes may appear in instance document. It also specifies where and how
often the elements may appear
• The schema specifies the datatype of every element and attributes of XML
• The XM L schemas are namespace-centric
DEFINING A SCHEMA
Schemas themselves are written with the use of a collection of tags, or a vocabulary, from a
namespace that is, in effect, a schema of schemas. The name of this namespace is
http://www.w3.org/2001/XMLSchema.
• Every schema has schema as its root element This namespace specification appears as
follows: xmlns:xsd = "http://www.w3.org/2001/XMLSchema"
127 | P a g e VSISCM
128 | P a g e VSISCM
• Third, the instance document must specify the filename of the schema in which the default
namespace is defined. This is accomplished with the schemaLocation attribute, which takes
two values: the namespace of the schema and the filename of the schema.
• xsi:schemaLocation = ’http://cs.uccs.edu/planeSchemaplanes.xsd’
SIMPLE TYPES
• Elements are defined in an XML schema with the element tag.
• <xsd:element name = "engine" type = "xsd-.string" />
• An instance of the schema in which the engine element is defined could have the following
element: <engine> inline six cylinder fuel injected </engine>
• An element can be given a default value with the default attribute:
• <xsdselement name = "engine" type « "xsdsstring"
• default » "fuel injected V-6" />
• Constant values are given with the fixed attribute, as in the following example:
• <xsd:element name - "plane" type - "xsdsstring" fixed = "single wing" />
• A simple user-defined data type is described in a simpleType element with the use of facets.
• Facets must be specified in the content of a restriction element, which gives the base type
name.
• The facets themselves are given in elements named for the facets: the value attribute specifies
the value of the facet.
129 | P a g e VSISCM
COMPLEX TYPES
Complex types are defined with the complexType tag. The elements that are the content of
an element-only element must be contained in an ordered group, an unordered group, a choice, or a
named group. The sequence element is used to contain an ordered group of elements. Example:
130 | P a g e VSISCM
• The output of xsv is an XML document. When the tool is run from die command line, the
output document appears on the screen with no formatting, so it is a bit difficult to read. The
following is the output of xsv run on planes. xml:
131 | P a g e VSISCM
• XSLT style sheets are XML documents, so they can be validated against DTDs.
• They can even be transformed with the use of other XSLT style sheets.
• The XSLT standard is given at http://www.w3.org/TR/xslt.
• XPath is a language for expressions, which are often used to identify parts of XML
documents, such as specific elements that are in specific positions in the document or elements
that have particular attribute values.
• XPath is also used for XML document querying languages, such as XQL, and to build new
XML document structures with XPointer.
• The XPath standard is given at http://www.w3.org/TR/xpath.
XSLT
• XSLT is actually a simple functional-style programming language.
• Included in XSLT are functions, parameters, names to which values can be bound, selection
constructs, and conditional expressions for multiple selection.
• XSLT processors take both an XML document and an XSLT document as input T
• he XSLT document is the program to be executed; the XML document is the input data to the
program.
• Parts of the XML document are selected, possibly modified, and merged with parts of the
XSLT document to form a new document, which is sometimes called an XSL document.
• The transformation process used by an XSLT processor is shown in Figure 7.5.
• Figure 7.5 XSLT processing
•
• An XSLT document consists primarily of one or more templates.
• Each template describes a function that is executed whenever the XSLT processor finds a
match to the template's pattern.
132 | P a g e VSISCM
• One XSLT model of processing XML data is called the template-driven model, which works
well when the data consists of multiple instances of highly regular data collections, as with
files containing records.
• XSLT can also deal with irregular and recursive data, using template fragments in what is
called the data-driven model.
• A single XSLT style sheet can include the mechanisms for both the template- and data-driven
models.
XML PROCESSORS
• The XML processor takes the XML document and DTD and processes the information so that
it may then be used by applications requesting the information.
• The processor is a software module that reads the XML document to find out the structure and
content of the XML document.
• The structure and content can be derived by the processor because XML documents contain
self-explanatory data.
133 | P a g e VSISCM
• The syntactic structures of interest naturally include opening tags, attributes, text, and closing
tags.
• The interfaces that describe the event handlers form the SAX API.
WEB SERVICES
A Web service is a method that resides and is executed on a Web server, but that can be called
from any computer on the Web. The standard technologies to support Web services are WSDL,
UDD1, SOAP, and XML.
• WSDL - It is used to describe the specific operations provided by the Web service, as well as
the protocols for the messages the Web service can send and receive.
134 | P a g e VSISCM
• UDDI - also provides ways to query a Web services registry to determine what specific
services are available.
• SOAP - was originally an acronym for Standard Object Access Protocol, designed to describe
data objects.
• XML - provides a standard way for a group of users to define the structure of their data
documents, using a subject-specific mark-up language.
135 | P a g e VSISCM
136 | P a g e VSISCM
137 | P a g e VSISCM