Web Technologies
Web Technologies
in
Unit – I
Hypertext Markup Language (HTML)
Basics:
What Is the Internet?
accessed and linked together in form of web sites. The World Wide Web
is a way of exchanging information between computers on the Internet,
tying them together into a vast collection of interactive multimedia
resources. It has a unique combination of flexibility, portability and user-
friendly features that distinguish it from other services provided by the
Internet. The main reason for its popularity is the use of a concept called
hypertext. It uses the client-server model, and an Internet protocol called
hypertext transport protocol (HTTP) for interaction between the
computers on the Internet. An English scientist Tim Berners-Lee invented
the World Wide Web in 1989 at CERN in Geneva.
URL
URL stands for Uniform Resource Locator, and is used to specify
addresses on the World Wide Web. A URL is the fundamental network
identification for any resource connected to the web (e.g., hypertext
pages, images, and sound files). It is a reference (an address) to a
resource on the Internet.
A URL will have the following format −
protocol://domain name:port/path
A URL has two main components:
Protocol Identifier: The protocol specifies how information is
transferred from a link. The protocol used for web resources is
Hyper Text Transfer Protocol (HTTP).
Domain name: The protocol is followed by a colon, two slashes,
and then the resource name-domain name. The domain name is
the complete address to the resource. The domain name is the
computer on which the resource is located.
Ex: http://google.com - here the protocol identifier is http, the
domain name is google.com
Web Server:
A web server is a computer system that processes requests
via HTTP to serve the files that form web pages to users, in
response to their requests.
The term can refer to the entire system, or specifically to
the software that accepts and supervises the HTTP requests.
The primary function of a web server is to store, process and
deliver web pages to clients.
When client sends request for a web page, the web server search
for the requested page if requested page is found then it will send
it to client with an HTTP response. If the requested web page is
not found, web server will the send an HTTP response: Error 404
Not found.
The most commonly used Web servers are Apache, which has
been implemented for a variety of computer platforms, and
Microsoft’s Internet Information Server (IIS), which runs under
Windows operating systems and XAMPP
Most ISPs offer several types of internet access which essentially differ in
connection speed – the time taken for download and upload. There exist
several ways to connect to the internet. Following are the connection
types available:
1. Dial-up Connection- connection is probably the slowest
connection and requires you to connect to the internet via your
phone line by dialing a number specified by the ISP. It requires
a modem to setup dial-up connection,
2. ISDN - ISDN is acronym of Integrated Services Digital
Network. It establishes the connection using the phone lines
which carry digital signals instead of analog signals.
3. DSL - is acronym of Digital Subscriber Line. It is a form of
broadband connection as it provides connection over ordinary
telephone lines. It is indeed very fast and these ISPs can offer
different download speeds – quicker the speed, higher will be
the price.
4. Cable TV Internet connections – this connection is provided through
URL
URL stands for Uniform Resource Locator, and is used to specify
addresses on the World Wide Web. A URL is the fundamental network
identification for any resource connected to the web (e.g., hypertext
pages, images, and sound files). It is a reference (an address) to a
resource on the Internet.
A URL will have the following format −
protocol://domain name:port/path
A URL has two main components:
Protocol Identifier: The protocol specifies how information is
transferred from a link. The protocol used for web resources is
Hyper Text Transfer Protocol (HTTP). Other protocols compatible
with most web browsers include FTP, telnet, newsgroups, and
Gopher.
Domain name: The protocol is followed by a colon, two slashes,
and then the resource name-domain name. The domain name is
the complete address to the resource. The domain name is the
computer on which the resource is located. Links to particular
files or subdirectories may be further specified after the domain
name. The directory names are separated by single forward
slashes.
Ex: http://google.com - here the protocol identifier is http, the domain
name is google.com
Domain Name:
What is HTML?
HTML stands for Hyper Text Markup Language, which is the
most widely used language on Web to develop web pages.
HTML was created by Tim Berners-Lee in late 1991 but
"HTML 2.0" was the first standard HTML specification which
was published in 1995.
HTML 4.01 was a major version of HTML and it was published
in late 1999. Though HTML 4.01 version is widely used but
currently we are having HTML-5 version which is an extension
to HTML 4.01, and this version was published in 2012.
It is a markup language and is a set of markup tags. The tags
describe document content.
HTML documents contain HTML tags and plain text, HTML
documents are also called web pages
HTML Tags
In a web page, the first tag <html> indicates the markup language that is
being used for the document. The <head> tag contains information about
the web page. Lastly, the content appears in the <body> tag. The
following illustration provides a summary.
Heading tags - <h1> </h1 >: Headings are defined with the <h1> to
<h6> tags. <h1> defines the largest heading while <h6> defines the
smallest.
Ex: <h1> This is my first Web Page </h1>
<h6> This is my first web page </h6>
HTML automatically adds an extra blank line before and after a heading.
A useful heading attribute is having “align” attribute with 3 values as
“left”, “right”, “center”.
Ex: <h5 align="left">I can align headings </h5>
<h5 align="center">This is a centered heading </h5>
<h5 align="right">This is a heading aligned to the right </h5>
Paragraph tag <p> </p>: Paragraphs are defined with the <p> and </p>
tag. Think of a paragraph as a block of text. Most content on a simple
web page will appear in paragraphs or sections. A lot of text can appear
within the <p> and </p> tags, and browsers will automatically wrap the
text onto the next line once it reaches the edge of the screen. You can
use the align attribute with a paragraph tag as well.
Ex: <p align="left">This is a paragraph</p>
Bold - <b> </b>: The text in between the tags will be bold, and stand
out against text around it, the same as in a word processor.
Line Break Tag - </br> : Whenever you use the <br> element, anything following it starts
from the next line. This tag is an example of an empty element, where you do not need closing
tag, as there is nothing to go in between them.
Ex: <p>This <br> is a para<br> graph with line breaks</p>
o/p: This
is a para
graph with line breaks
Preformatted Text - <pre> </pre>: Any text between the pre tags,
including spaces, carriage returns and punctuation, will appear in the
browser as it is typed in the text editor (normally browsers ignore multiple
spaces)
Small - <small> </small>: Instead of having to set a font size, you can
use the small tag to render text slightly smaller than the text around it.
Big - <big> </big> : It displays the text in slightly bigger size than the
text around it.
Font tag: <font> </font>: the font tag is used to change the color, size,
style of the font tag.
Links in HTML
A webpage can contain various links that take you directly to
other pages or other websites, and even specific parts of a given
page. These links are known as hyperlinks.
Hyperlinks allow visitors to navigate between Web sites by
clicking on words, phrases, and images. Thus you can create
hyperlinks using text or images available on a webpage or any
other HTML element.
A link is specified using HTML <a>. This tag is called anchor
tag and anything between the opening <a> tag and the closing
</a> tag becomes part of the link and a user can click that part to
reach to the linked document.
domain. The menu bar at the top of your site includes internal
links. Links from pages on your site to your contact page are
another simple example of internal links. This link can be absolute
path or relative path.
Syntax of anchor tag <a> …</a>
Syntax: <a href=”document URL ” attributes> link text </a>
Ex: <a href="home.html"> My homepage </a>
There are two main parts in link:
1. The href is an attribute that specifies the destination address
(URL) where to go. In the above example home.html is
destination address.
2. The link text that is the visible text in between <a> and </a>.
Clicking on the link text will send you to the specified address.
Link text generally will be displayed in blue color with underline.
In the above example MY homepage is link text.
Ex: <a href="https://www.google.com/">Google Search</a>
Target attribute of hyperlink: The target attribute specifies where to
open the linked document.
The target attribute can have one of the following values:
_blank - Opens the linked document in a new window or tab
_self - Opens the linked document in the same window/tab as it
was clicked (this is default)
_parent - Opens the linked document in the parent frame
_top - Opens the linked document in the full body of the window
framename - Opens the linked document in a named frame
Ex1: <a href="https://www.google.com/" target="_blank">Google</a>
Ex2: <a href="https://www.tutorialrepublic.com/" target="_top">Tutorial</a>
the referenced page. You may notice that the image gets a blue
border just as link text became underlined. This can be resolved by
setting the border="0" attribute of the image, or using css.
Ex1: <a href="kites.jpg"><img src="kites-thumb.jpg" alt="kites"></a>
Ex2: <a href="sky.jpg" target="_self"><img src="sky-thumb.jpg" alt="Cloudy Sky"></a>
<img> tag: To display an image you need to specify the URL of the
image using the src attribute, replacing url with the filename of image. it
contains attributes only, and does not have a closing tag.There are several ways this can be
done:
src="picture.jpg" - the filename if the image is in the same directory
as the html file.
src="images/picture.jpg" - a relative path when the image is in
another directory.
src="http://www.simplehtmlguide.com/images/photo.jpg" - a full URL
can also be used.
Alternate Text - <img ... alt="?">: The alt attribute defines the text
shown in place of an image when the image cannot load.
code(as with any other tag). However, you can align an image with
the surrounding text or paragraph by setting any of align="left | right
| top | bottom | middle".
HTML Tables
Table tags are used for displaying data in rows and columns. The HTML
tables allow web authors to arrange data like text, images, links, other
tables, etc. into rows and columns of cells.
The HTML tables are created using the <table> tag in which the A
table is divided into rows with the <tr> tag, which stands for table row,
and each row is divided into data cells with the <td> tag, which stands for
table data. A <td> tag can contain text, links, images, lists, forms, other
tables, etc.
<table> ... </table>: Used to define a table, it contains all row and
column tags along with their content. It has some attributes to define the
table layout.
border="?" - The size of the border (in pixels) surrounding the table
cellspacing="?" - The space (in pixels) between each cell, eg.
between rows or columns.
cellpadding="?" - The space, or margin, between the content of a
cell and its border.
<tr> </tr>: To start a table row, the tr tags must appear within the table
tags.
<td> </td>:A table cell is where the content goes. Cells must exist within
rows, where the number of cells in a row determines the number of
columns in the table.
<html>
<body>
<table border="1">
<tr>
<th>Header 1</td>
<th>Header 2</td>
</tr>
<tr>
<td>Cell A1</td>
<td>Cell B1</td>
</tr>
<tr>
<td>Cell A2</td>
<td>Cell B2</td>
</tr>
</table>
</body>
</html>
Row 3 Cell 1
HTML Forms
What is HTML Form
HTML Forms are required to collect different kinds of user
inputs, such as contact details like name, email address, phone
numbers, or details like credit card information, etc.
Forms contain special elements called controls like input box,
check boxes, radio-buttons, submit buttons, etc.
Users generally complete a form by modifying its controls e.g.
entering text, selecting items, etc. and submitting this form to a
web server for processing.
The <form> tag is used to create an HTML form.
Form - <form> ... </form>: All form elements such as inputs and buttons
must go within the form tags. In most cases, a form must have the name,
action & method attributes set.
name="?" - A unique name identifying the form, used by the
action script.
action="url" - The address (URL) of the script that will process
the form data when submitted.
method="?" - The method used by the action script, post or
get. For example, post would be used to submit data to a user-
registration form, and get is used for searches or forms that
must return information.
Input Field - <input>: Used to create a simple text-entry field for your form,
but is also the basis for many other form input types using the type attribute. An
input element can be of type text field, checkbox, password field, radio
button, submit button, reset button, etc.
Note: The form itself is not visible. Also note that the default width of a
text field is 20 characters.
Password Field:
<input type="password"> defines a password field:
Ex: <form>
Password: <input type="password" name="pwd">
</form>
How the HTML code above looks in a browser:
Password:
Checkboxes:
<input type="checkbox"> defines a checkbox. Checkboxes let a user
select ZERO or MORE options of a limited number of choices.
Ex: <form>
<input type="checkbox" name="vehicle" value="Bike">I have a bike<br>
<input type="checkbox" name="vehicle" value="Car">I have a car
</form>
How the HTML code above looks in a browser:
I have a bike
I have a car
Submit Button:
<input type="submit"> defines a submit button.
A submit button is used to send form data to a server. The data is sent to
the page specified in the form's action attribute. The file defined in the
action attribute usually does something with the received input:
Ex: <form name="input" action="demo_form_action.asp" method="get">
Username: <input type="text" name="user">
<input type="submit" value="Submit">
</form>
How the HTML code above looks in a browser:
Username:
If you type some characters in the text field above, and click the "Submit"
button, the browser will send your input to a page called
"demo_form_action.asp". The page will show you the received input.
Ex: <FORM action="http://somesite.com/prog/adduser" method="post">
<P> First name: <INPUT type="text" name="firstname"><BR>
Last name: <INPUT type="text" name="lastname"><BR>
email: <INPUT type="text" name="email"><BR>
<INPUT type="radio" name="gender" value="Male"> Male<BR>
<INPUT type="radio" name="gender" value="Female"> Female<BR>
<BUTTON name="submit" value="submit" type="submit">
Send<IMG src="/icons/wow.gif" alt="wow"></BUTTON>
<BUTTON name="reset" type="reset">
Reset<IMG src="/icons/oops.gif" alt="oops"></BUTTON>
</P>
</FORM>
Unit – II
What is CSS?
CSS stands for Cascading Style Sheets. Styles define how
to display HTML elements.
CSS is a design language intended to simplify the process
of making web pages presentable.
CSS handles the look and feel part of a web page.
Using CSS, 1) you can control the color of the text, the style
of fonts, the spacing between paragraphs, how columns are
sized and laid out, what background images or colors are
used, layout designs, and variations in display for different
devices and screen sizes as well as a variety of other effects.
2) Saves a lot of time - CSS style definitions are saved in external CSS
files so it is possible to change the entire website by changing just one file.
3) Provide more attributes - CSS provides more detailed attributes than
plain HTML to define the look and feel of the website.
Advantages of CSS:
CSS saves time - You can write CSS once and then reuse
same sheet in multiple HTML pages. You can define a style
for each HTML element and apply it to as many Web pages
as you want.
Pages load faster - If you are using CSS, you do not need to
write HTML tag attributes every time. Just write one CSS
CSS Syntax:
A CSS comprises of style rules that are interpreted by the browser and
then applied to the corresponding elements in your document. A style
rule is made of three parts:
Selector: A selector is an HTML tag at which style will be
applied. This could be any tag like <h1> or <table> etc.
Property: A property is a type of attribute of HTML tag. Put
simply, all the HTML attributes are converted into CSS
CSS
command element {property: value;}
tag
CSS Types (CSS Styles): There three ways of applying a style sheet:
1. External style sheet
2. Internal style sheet
3. Inline style
</head>
An external style sheet can be written in any text editor. The file
should not contain any html tags. Your style sheet should be saved
with a .css extension. An example of a style sheet file is shown
below:
hr {color: sienna;}
p {margin-left:20px;}
body {background-image: url("images/back40.gif");}
3. Inline Styles
An inline style loses many of the advantages of style sheets by
mixing content with presentation. Use this method sparingly!
To use inline styles you use the style attribute in the relevant tag.
The style attribute can contain any CSS property. The example
shows how to change the color and the left margin of a paragraph:
CSS Selectors:
The different styles that we can use to apply on css elements can be
done by using different types of css selectors.
chosen to select a single, unique element. It is written with the hash character
(#), followed by the id of the element. Let’s take an example with the id "para1".
<html>
<head>
<style>
#para1 { text-align: center; color: blue; }
</style>
</head>
<body>
<p id="para1">Hello CSS </p>
<p>This paragraph will not be affected.</p>
</body>
</html>
3) CSS Class Selector: The class selector selects HTML elements with a
specific class attribute. It is used with a period character. (full stop symbol)
followed by the class name.
<!DOCTYPE html>
<html>
<head>
<style>
.center { text-align: center; color: blue; }
</style>
</head>
<body>
<h1 class="center">This heading is blue and center-
aligned.</h1>
<p class="center">This paragraph is blue and center-
aligned.</p>
</body>
</html>
4) CSS Universal Selector: The universal selector is used as a wildcard
character. It selects all the elements on the pages.
<!DOCTYPE html>
<html>
<head>
<style>
* { color: green; font-size: 20px; }
</style>
</head>
<body>
<h2>This is heading</h2>
<p>This style will be applied on every paragraph.</p>
<p id="para1">Me too!</p>
<p>And me!</p>
</body>
</html>
5) CSS Group Selector: The grouping selector is used to select all the elements
with the same style definitions. Grouping selector is used to minimize the code.
Commas are used to separate each selector in grouping.
<html>
<head>
<style>
h1, h2, p { text-align: center; color: blue; }
</style>
</head>
<body>
<h1>Hello Javatpoint.com</h1>
<h2>Hello Javatpoint.com (In smaller font)</h2>
<p>This is a paragraph.</p>
</body>
</html>
<div>
<p>contents of div</p>
</div>
The DIV element allows you to define the style of entire sections of
the HTML. You can define a division of your page as a callout and
give that area a different style from the surrounding text. That area
may have images, paragraphs, and headlines anything you wanted.
The DIV element also gives you the ability to identify unique areas of
Example:
<html>
<body>
<div style="background-color: black;
color: white;
padding: 20px;">
<h2>London</h2>
<p>London is the capital city of England. It is the most populous city
in the United Kingdom, with a metropolitan area of over 13 million
inhabitants.</p>
<p>Standing on the River Thames, London has been a major
settlement for two millennia, its history going back to its founding by
the Romans, who named it Londinium.</p>
</div>
</body>
</html>
CSS3:
Cascading Style Sheets Level 3 (CSS3) is the iteration of the CSS
standard used in the styling and formatting of Web pages. CSS3
CSS3 Borders:
A CSS3 Border is such an afford of style sheet which reduces the
human efforts of Photoshop and other graphical applications. An
individual can create the rounded borders, border shadow, imaged
based border and etc. with the help of CSS3 Border. Basically we use
three features to create the border:
border-radius
box-shadow
border-image
height: 150px;
}
border-radius Use this element for setting four boarder radius
property
border-top-left- Use this element for setting the boarder of top
radius left corner
border-top-right- Use this element for setting the boarder of top
radius right corner
border-bottom- Use this element for setting the boarder of
right-radius bottom right corner
border-bottom-left- Use this element for setting the boarder of
radius bottom left corner
Ex: <html>
<head>
<title>Title Name will go here</title>
</head>
<style>
#border_radius
{
border:10px solid;
font-size: 24px;
color: #00ff00;
font-weight: bold;
padding: 10px;
background: #000FCF;
border-top-left-radius:25px;
border-bottom-right-radius:25px;
}
#border_image
{
border-width: 15px;
border-radius:15px;
border-image:url(tulips.jpg) 30 30 round; /* Firefox */
border-image:url(4.jpg) 30 30 round; /* Safari and
Chrome */
}
</style>
<body>
<div id="border_radius"> With the help of border-radius
properties, we can make the rounded corners border. </div>
<div id="border_image"> You can see the customized
border. This could be either *.png or *.jpg format. </div>
</body>
</html>
CSS3 Background:
CSS3 provided several new background properties which facilitate
background control. The newly specified properties in CSS3 for
background are:
background-clip Specifying the painting area of the background images
background-origin Where the background will be painted
background-size Determining the size of the background-image
Background-clip:
The background-clip property defines how far the background (color
or image) should extend within an element. We can make the
background cover just the padding-box or just the content-box with
the help of background-clip. Clipping means cutting out and not
displaying what falls outside the clipping region. It lets you control
how far a background image or color extends beyond an element's
padding or content.
Syntax:
background-clip: border-box|padding-box|content-box;
Values:
border-box is the default value. This allows the background
to extend all the way to the outside edge of the element's
border.
padding-box clips the background at the outside edge of the
element's padding and does not let it extend into the border.
content-box clips the background at the edge of the content
box.
Background-size:
It's sometime needed to specify a certain size to the background
image.To control the background image size, all you need to do is to
use background-size property in body selector as will be shown in the
following code.
<!DOCTYPE html>
<html>
<head>
<title>CSS3 Modules: borders &background </title>
<style>
body {
background:url(tulips.jpg);
background-size:180px 160px;
background-repeat: no-repeat;
}
</style>
</head>
<body>
</body>
</html>
Note: if you didn't specify background-repeat property to no-repeat, it
will repeat the images several times. To use the original size of the
image just set the background dimensions to auto, instead of using
values.
Background-image:
The background-image property in CSS applies a graphic (e.g. PNG,
SVG, JPG, GIF, WEBP) or gradient to the background of an element.
The background-image property sets one or more background images
for an element. By default, a background-image is placed at the top-
left corner of an element, and repeated both vertically and
horizontally. There are two different types of images you can include
with CSS: regular images and gradients.
Tip: The background of an element is the total size of the element,
including padding and border (but not the margin).
Syntax:
background-image: url|none;
values:
URL: the URL of the image. To specify more than one
image, separate with comma.
None: No background image will be displayed. This is
default.
linear-gradient():Sets a linear gradient as the background
image. Define at least two colors (top to bottom)
radial-gradient( ):Sets a radial gradient as the background
image. Define at least two colors (center to edges)
repeat-linear-gradient( ):repeats the linear gradient
repeat-radial-gradient( ):repeats the radial gradient.
Ex1: body {
background-image: url("img_tree.gif"), url("paper.gif");
background-color: #cccccc;
}
Ex2: body {
background-image: url("img_tree.gif"), url("paper.gif");
background-repeat: no-repeat, repeat;
background-color: #cccccc;
}
Ex3: #grad1 {
height: 250px;
width:400px;
padding:50px;
background-image: linear-gradient(orange, white, green);
}
Text-Effects:
CSS3 contains several new text features. In this chapter we will learn
about the following properties:
text-overflow
word-wrap
word-break
Properties provided by CSS3 for text editing is showing below:
text-emphasis Applies emphasis marks
text-justify Justify text
text-outline Specifies a text outline
text-overflow Specify behavior is the text overflow it's container
text-shadow Add shadow to the text , “like fire and ice”
text-wrap Wrap text into multiple lines according to certain delimiter
word-break Specifies line breaking rules
Break long words and divide them to more than one line
word-wrap like:immunosuppressive which can make it immune-
suppressive
Text-Overflow:
The text-overflow property specifies how overflowed content
that is not displayed should be signaled to the user. It can be
clipped, display an ellipsis (...), or display a custom string.
Both of the following properties are required for text-overflow:
white-space: nowrap;
overflow: hidden;
The CSS text-overflow property specifies how overflowed
content that is not displayed should be signaled to the user.
The text-overflow property only affects content that is
overflowing a block container element in its inline progression
direction (not text overflowing at the bottom of a box, for
example).
Syntax:
text-overflow: clip | ellipsis | string ;
Values:
Clip Default value. The text is clipped and not accessible
Ex: <style>
div.a {
white-space: nowrap;
width: 50px;
overflow: hidden;
text-overflow: clip;
border: 1px solid #000000;
}
div.b {
white-space: nowrap;
width: 50px;
overflow: hidden;
text-overflow: ellipsis;
border: 1px solid #000000;
}
</style>
Word-wrapping:
Sometimes, while writing in a container on a web page, the
end of line is not displayed properly. The solution was
provided CSS3 in word-wrap property which wrap the long
words to the next line.
The CSS word-wrap property allows long words to be able
to be broken and wrap onto the next line.
If a word is too long to fit within an area, it expands outside;
The word-wrap property allows you to force the text to wrap
- even if it means splitting it in the middle of a word.
Syntax:
Word-break:
The word-break property in CSS can be used to change
when line breaks ought to occur.
Normally, line breaks in text can only occur in certain
spaces, like when there is a space or a hyphen. It specifies
how words should break when reaching the end of a line.
Syntax:
word-break: normal | break-all | keep-all | break-word;
Values:
normal: use the default rules for word breaking.
break-all: any word/letter can break onto the next line.
keep-all: for Chinese, Japanese and Korean text words are
not broken. Otherwise this is the same as normal.
break-word: to prevent overflow, word may be broken at
arbitrary points.
Ex: p {
word-break: break-all;
}
Web Fonts:
Web fonts allow Web designers to use fonts that are not installed on
the user's computer. When you have found/bought the font you wish
to use, just include the font file on your web server, and it will be
automatically downloaded to the user when needed. Your "own" fonts
are defined within the CSS @font-face rule.
CSS3 Transforms:
Using the new CSS3 transform property you can create element
transformations and to change the shape, size and position of the
element. 2D transforms are used to re-change the element structure.
The transform property can get a set of transformation functions
which can be composed if you write them separated by whitespace.
The 2D transform functions included:
translate – given left and top parameters, the element will
move from its position to the new point. There are also a
translateX and translateY functions that get only one
parameter and translate the element only in one axis.
rotate – given a degree the element rotate clockwise
according to the degree. Pay attention that the parameter
should be in a specific format for example these are valid
parameters: 60deg, 80deg and etc.
CSS transitions
Introduction:
Defining transitions
CSS Transitions are controlled using the shorthand transition property.
You can control the individual components of the transition with the
following sub-properties:
There are 4 sub-properties that are required in order for the transition
to take effect:
1. transition-property
2. transition-duration
3. transition-timing (optional)
4. transition-delay (optional)
Here’s the full shorthand sequence. Again, the first two properties are
required.
div {
transition: [property] [duration] [timing-function] [delay];
}
1. transition-property (required)
2. transition-duration (required)
3. transition-timing (optional)
in-out.
Here’s an example of the different timing options (used with
the transform: translateproperty):
For more advanced timing options, you can define a custom timing
function with a cubic-bezier.
CSS syntax example:
div {
transition-timing-function: ease-in-out;
}
Shorthand example:
div {
transition: all 3s ease-in-out;
}
4. transition-delay (optional)
UNIT-III
Introduction:
JavaScript is a dynamic scripting language. JavaScript is the most popular scripting language on
the internet, and works in all major browsers, such as Internet Explorer, Mozilla, Firefox,
Netscape, Opera.
JavaScript was first known as LiveScript, but Netscape changed its name to JavaScript.
JavaScript made its first appearance in Netscape 2.0 in 1995 with the name LiveScript.
7. JavaScript is used in millions of Web pages to improve the design, validate forms,
detect browsers, create cookies, and much more.
Interoperability. JavaScript plays nicely with other languages and can be used in a
huge variety of applications. Unlike PHP or SSI scripts, JavaScript can be inserted
into any web page regardless of the file extension. JavaScript can also be used
inside scripts written in other languages such as Perl and PHP.
Rapid Development: JavaScript syntax's are easy and flexible for the developers.
JavaScript small bit of code you can test easily on Console Panel (inside Developer
Tools) at a time browser interpret return output result. In-short easy language to get
pick up in development.
Speed. Client-side JavaScript is very fast because it can be run immediately within
the client-side browser. Unless outside resources are required, JavaScript is
unhindered by network calls to a backend server. It also has no need to be compiled
on the client side which gives it certain speed advantages.
User Interface Interactivity: JavaScript used to fill web page data dynamically such
as drop-down list for a Country and State. Base on selected Country, State drop
down list dynamically filled. Another one is Form validation, missing/incorrect fields
you can alert to a users using alert box.
JavaScript can be implemented using JavaScript statements that are placed within
the <script>... </script> HTML tags in a web page.
You can place the <script> tags, containing your JavaScript, anywhere within your web page,
but it is normally recommended that you should keep it within the <head> tags.
Language − This attribute specifies what scripting language you are using.
Typically, its value will be javascript. Although recent versions of HTML (and
XHTML, its successor) have phased out the use of this attribute.
There is a flexibility given to include JavaScript code anywhere in an HTML document. However
the most preferred ways to include JavaScript in an HTML file are as follows −
The <script> tag alerts the browser program to start interpreting all the text between these tags
as a script. A simple syntax of your JavaScript will appear as follows.
JavaScript code
</script>
Ex: <html>
<body>
document.write("Hello World!")
</script>
</body>
</html>
JavaScript provides different data types to hold different types of values. There are two types of
data types in JavaScript.
JavaScript is a dynamic type language, means you don't need to specify type of the variable
because it is dynamically used by JavaScript engine. You need to use var here to specify the data
type. It can hold any type of values such as numbers, strings etc. For example:
Primitive data types: these are the primary data types in javaScript
Boolean- A value which can ony be either true or false.
String: A group of characters represents string. i.e text. A string can be enclosed by
a pair of single quotes (') or double quote (").
Eg: “welcome”
Null – it defines a single value, the only value is "null" – to represent nothing.
Undefined: represents undefined value. The only value is "undefined" – to represent
the value of an uninitialized variable.
JavaScript Variables:
Like many other programming languages, JavaScript has variables. Variables can be thought of
as named containers. You can place data into these containers and then refer to the data simply
by naming the container.
Before you use a variable in a JavaScript program, you must declare it. Variables are declared
with the var keyword as follows.
We create variables and assign values to them in the following way:
var christianName = "Fred" (string)
var surname = "Jones" (string)
var age = 37 (numeric)
var married = false (Boolean)
When a new variable is created (or declared) its name must be preceded by the
word var
The type of the variable is determined by the way it is declared:
if it is enclosed within quotes, it's a string
if it is set to true or false (without quotes) it's a boolean
if it is a number (without quotes) it's numeric
We refer to the equals sign as the assignment operator because we use it to assign
values to variables;
Variable names must begin with a letter or an underscore
Variable names must not include spaces
raise an alert, or to get confirmation on any input or to have a kind of input from the users. Here
we will discuss each dialog box one by one.
Alert Dialog Box: An alert dialog box is mostly used to give a warning message to the users.
It is used to show a message in the dialog box, and there is an OK button. It is mostly used to
prompt message if user missed input value or invalid data in given form or text. When an alert
box pops up, the user will have to click "OK" to proceed.
Syntax: window.alert("sometext");
Var price=10.00;
alert("The price is "+price);
Which produces:
Syntax: window.confirm("sometext");
Eg: if (confirm("Press a button!"))
{
txt = "You pressed OK!";
}
else
{
txt = "You pressed Cancel!";
}
Prompt Dialog Box:
The prompt dialog box is very useful when you want to pop-up a text box to get user input. Thus,
it enables you to interact with the user. The user needs to fill in the field and then click OK. This
dialog box has two buttons: OK and Cancel. If the user clicks the OK button, the window
method prompt() will return the entered value from the text box. If the user clicks the Cancel
button, the window method prompt()returns null.
Syntax: window.prompt("sometext","defaultText");
Eg:
document.write() method – this method is used to display the data on to the screen.
Eg: document.write(“welcome”)
document.write(23)
JavaScript Operators:
Operators are a type of command. They perform operations on variables and/or literals and
produce a result.
Relational (Comparison) Operators: <, <=, >, >=, !=, !==, == and ===(this will
check with type of data also).
===, !== (Strictly equals and strictly not equals) i.e., Type and value of operand must
match / must not match
Eg: var v2 = ("5" === 5); // false
var v3 = (5 === 5.0); // true
Logical Operators:
1. ! – Logical NOT-
!OP1
!0=1 and !1=0 i.e !(true)=false, !(false)=true
2. && – Logical AND
OP1 && OP2
If OP1 is true, expression evaluates to the value of OP2.
Otherwise the expression evaluates to the value of OP1.
Results may not be a boolean value.
3. || – Logical OR
OP1 || OP2
If OP1 is true, expression evaluates to the value of OP1. Otherwise the expression
evaluates to the value of OP2.
Assignment Operators: =, +=, -=,*=, /=, %=. These are shorthand assignment
operators.
Eg: a=5 a+=2 means a=a+2 i.e a=5=2 a=7
Conditional (or ternary) Operator:
"? :" ternary conditional statement. It works like if-else statement.
Exp1? Exp2 : Exp3 here exp1 is a condition if this conditions gives true value then exp2
will be evaluated. If exp1 condition is false then exp3 will be evaluated.
Eg: big = (a>b) ? a : b
Arrays:
An array is an object
Contains data elements in sequential order
Use else to specify a block of code to be executed, if the same condition is false
Use else if to specify a new condition to test, if the first condition is false
if statement:
if(condition)
{
block of code to be executed if the condition is true
}
Here a condition is evaluated. If the resulting value is true, the given statement(s) are executed. If
the expression is false, then no statement would be not executed.
Eg: <script>
var a=20;
if(a>10){
document.write("value of a is greater than 10");
}
</script>
The else Statement: Use the else statement to specify a block of code to be executed if the
condition is false. The syntax is as follows:
if (condition)
{
block of code to be executed if the condition is true
}
else
{
block of code to be executed if the condition is false
}
Here JavaScript condition is evaluated. If the resulting value is true, the given statement(s) in the
‘if’ block, are executed. If the expression is false, then the given statement(s) in the else block are
executed.
Eg: <script>
var a=20;
if(a%2==0)
{
document.write("a is even number");
}
else
{
document.write("a is odd number");
}
</script>
if...else if... statement: The if...else if... statement is an advanced form of if…else that allows
JavaScript to make a correct decision out of several conditions.
Syntax: The syntax of an if-else-if statement is as follows –
if (condition1) {
block of code to be executed if condition1 is true
} else if (condition2) {
block of code to be executed if the condition1 is false and condition2 is true
} else {
block of code to be executed if the condition1 is false and condition2 is false
}
Eg: if (time < 10) {
greeting = "Good morning";
} else if (time < 20) {
greeting = "Good day";
} else {
greeting = "Good evening";
}
This will stop the execution of more code and case testing inside the block.
When a match is found, and the job is done, it's time for a break. There is no need
for more testing.
Syntax:
switch(expression)
{
case value1:
code to be executed;
break;
case value2:
code to be executed;
break;
......
default:
code to be executed if above values are not matched;
}
Eg: <script>
var grade='B';
var result;
switch(grade)
{
case 'A':
result="A Grade";
break;
case 'B':
result="B Grade";
break;
case 'C':
result="C Grade";
break;
default:
result="No Grade";
}
document.write(result);
</script>
Loops in JavaScript:
While writing a program, you may encounter a situation where you need to perform an action over
and over again. In such situations, you would need to write loop statements to reduce the number
of lines.
The JavaScript loops are used to iterate the piece of code using for, while, do while or for-in
loops. It makes the code compact. It is mostly used in array.
1. while loop
2. do-while loop
3. for loop
4. for-in loop
1) While loop:
The most basic loop in JavaScript is the while loop. The purpose of a while loop is to execute a
statement or code block repeatedly as long as an expression is true. Once the expression
becomes false, the loop terminates. The syntax is as follows:
while (condition)
{
code to be executed
}
Eg: <script>
var i=11;
while (i<=15)
{
document.write(i + "<br/>");
i++;
}
</script>
O/P: 11
12
13
14
15
2) 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, and then it will repeat the loop as long as the condition is true.
The loop will always be executed at least once, even if the condition is false, because the code
block is executed before the condition is tested.
Syntax
do {
code block to be executed
}
while (condition);
Eg: <script>
var i=21;
do{
document.write(i + "<br/>");
i++;
}while (i<=25);
</script>
O/P: 21
22
23
24
25
Eg: <script>
for (i=1; i<=5; i++)
{
document.write(i + "<br/>")
}
</script>
O/P : 1
2
3
4
5
4) The for…in loop:
The for...in loop is used to loop through an object's properties. Once you understand how
objects behave in JavaScript, you will find this loop very useful.
Syntax:
for(variable-name in object)
{
Functions in JavaScript:
A function is a group of reusable code which can be
called anywhere in your program. This eliminates
the need of writing the same code again and again.
It helps programmers in writing modular codes.
Functions allow a programmer to divide a big
program into a number of small and manageable
functions.
JavaScript supports: 1. built-in functions and 2.
User-defined functions.
{
return a * b;
}
Calling a Function
Declared functions are not executed immediately.
They will be executed later, when they are invoked
(called upon).To invoke a function somewhere later
in the script, you would simply need to write the
name of that function with parameters if any.
How to invoke a function:
Eg: we need to use html form objects to invoke a
function by a click action on a button.
<html>
<head>
<script type="text/javascript">
function sayHello()
{
document.write ("Hello there!");
}
</script>
</head>
<body>
<p>Click the following button to call the
function</p>
<form>
<input type="button" onclick="sayHello()"
value="Say Hello">
</form>
</body>
</html>
{
alert (number*number*number);
}
</script>
<form>
<input type="button" value="click" onclick="getcube(4)"
</form>
Objects in JavaScript:
In JavaScript, an object is defined as
"http://www.w3schools.com", //
Document URL
"my_new_window", // Window Name
"toolbar=yes,location=yes,directories=no,"
+
"status=no,menubar=yes,scrollbars=yes,"
+
“resizable=no,copyhistory=yes,width=400,heigh
);
else
{ // Otherwise close the opened
window
myWin.close();
myWin = null;
}
}
</script>
</head>
<body>
<form>
<input type="button" value="Open/close Window"
onclick="open_close_win()">
</form>
</body>
</html>
<form>
<input type="button" onclick="sayHello()" value="Say
Hello" />
</form>
</body>
</html>
Onmousedown and onmouseup events:
The onmousedown, onmouseup, and onclick events are all parts of a
mouse-click. First when a mouse-button is clicked, the onmousedown
event is triggered, then, when the mouse-button is released, the
onmouseup event is triggered, finally, when the mouse-click is
completed, the onclick event is triggered.
<!DOCTYPE html>
<html>
<head>
<script>
function lighton() {
document.getElementById('myimage').src = "bulbon.gif";
}
function lightoff() {
document.getElementById('myimage').src = "bulboff.gif";
}
</script>
</head>
<body>
<img id="myimage" onmousedown="lighton()"
onmouseup="lightoff()" src="bulboff.gif" width="100" height="180"
/>
<p>Click mouse and hold down!</p>
</body>
</html>
The onload and onunload Events:
The onload and onunload events are triggered when the user enters or
leaves the page. The onload event can be used to check the visitor's
browser type and browser version, and load the proper version of the
web page based on the information. The onload and onunload events
can be used to deal with cookies.
Ex: <!DOCTYPE html>
<html>
<head>
<script>
function mymessage() {
alert("This message was triggered from the onload event");
}
</script>
</head>
<body onload="mymessage()">
</body>
</html>
Forms:
A web form, also called an HTML form, is an online page that allows for user input. It
is an interactive page that mimics a paper document or form, where users fill out
particular fields.
HTML Forms are required to collect different kinds of user inputs, such as contact
details like name, email address, phone numbers, or details like credit card
information, etc.
Forms contain special elements called controls like input box, check boxes, radio-
buttons, submit buttons, etc.
Users generally complete a form by modifying its controls e.g. entering text,
selecting items, etc. and submitting this form to a web server for processing.
<body>
<FORM >
<P> First name: <INPUT type="text" name="firstname"><BR>
Last name: <INPUT type="text" name="lastname"><BR>
Email: <INPUT type="text" name="email"><BR>
<INPUT type="radio" name="gender" value="Male"> Male<BR>
<INPUT type="radio" name="gender" value="Female"> Female<BR>
<BUTTN name="submit" value="submit" type="submit">
Send <IMG src="/icons/wow.gif" alt="wow"></BUTTON>
<BUTTON name="reset" type="reset">
Reset<IMG src="/icons/oops.gif" alt="oops"></BUTTON>
</P>
</FORM>
</body>
The Form object:
The Utility of JavaScript in forms is to validate the data (data validation) before it gets
sent to server script for processing of data. Before submitting the data to the server data should
be validated i.e., it should be checked for the correctness of the data. Once the form has been
validated, the same script can be used to forward the data on to the server. It is used to check for
empty form fields, improperly filled forms, verify the correct format of email address, credit card
no, zipcode, telephone number etc.
JavaScript can also be used to submit the form on behalf of the user, using form object and its
methods, properties. It enables users to handle multiple forms, call function to handle events,
respond to various form related events etc.
submit() - Submits the form as though the submit button were pressed by the user.
length - The number of fields in the elements array. I.E. the length of the elements
array.
method - This is a read or write string. It has the value "GET" or "POST".
target - The name of the frame or window the form submission response is sent to
by the server. Corresponds to the FORM TARGET attribute.
Form Events
onReset
onSubmit
}
</script>
</head>
<body>
<form name="myForm" action="tryjs_submitpage.htm"
onsubmit="return validate()"
>
Enter a value (1-5):
<input type="text" name="myInput" size="20">
<input type="submit" value="Submit">
</form></body></html>
UNIT-IV
PHP
<?php
echo "Hello World!";
?>
</body>
</html>
PHP 5 echo and print Statements
In PHP there are two basic ways to get output: echo and print.
echo and print are more or less the same. They are both used to
output data to the screen.
The differences are small: echo has no return value
while print has a return value of 1 so it can be used in
expressions. echo can take multiple parameters (although such
usage is rare) while print can take one argument. echo is
marginally faster than print.
The PHP echo Statement
The echo statement can be used with or without parentheses
like echo or echo( ) to display text.
The following example shows how to output text with
the echo command (notice that the text can contain HTML
markup):
Example
<?php
echo "<h2>PHP is Fun!</h2>";
echo "Hello world!<br>";
echo "I'm about to learn PHP!<br>";
echo "This ", "string ", "was ", "made ", "with multiple
parameters.";
?>
Example
<?php
$txt1 = "Learn PHP";
$txt2 = "W3Schools.com";
$x = 5;
$y = 4;
Document that containing black fields, that the user can fill the data or
user can select the data. Forms are used to collect the data and
casually the data will store in the data base. The PHP super-global
$_GET and $_POST are used to collect form-data.
PHP - A Simple HTML Form
The example below displays a simple HTML form with two input
fields and a submit button:
Example
<html>
<body>
</body>
</html>
When the user fills out the form above and clicks the submit button,
the form data is sent for processing to a PHP file named
"welcome.php". The form data is sent with the HTTP POST method.
To display the submitted data you could simply echo all the variables.
The "welcome.php" looks like this:
<html>
<body>
</body>
</html>
</body>
</html>
Run example »
and "welcome_get.php" looks like this:
<html>
<body>
</body>
</html>
The code above is quite simple. However, the most important thing is
missing. You need to validate form data to protect your script from
malicious code.
GET:
Information sent from a form with the GET method is visible to
everyone. GET also has limits on the amount of information to send.
The limitation is about 2000 characters. GET may be used for sending
non-sensitive data. However, because the variables are displayed in
the URL, it is possible to bookmark the page.
POST:
Information sent from a form with the POST method is invisible to
others and has no limits on the amount of information to send.
Developers prefer POST for sending form data. However, because the
variables are not displayed in the URL, it is not possible to bookmark
the page.
machine.
Some of Validation rules for field
Validate Form Data With PHP
The first thing we will do is to pass all variables through PHP's
htmlspecialchars() function.
When we use the htmlspecialchars() function; then if a user tries to submit
the following in a text field:
<script>location.href('http://www.hacked.com')</script>
Bottom of Form
The validation rules for the form above are as follows:
Field Validation Rules
Name Required. + Must only contain letters and whitespace
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = test_input($_POST["name"]);
$email = test_input($_POST["email"]);
$website = test_input($_POST["website"]);
$comment = test_input($_POST["comment"]);
$gender = test_input($_POST["gender"]);
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
URL and E-Mail Validation in PHP:
You can validate data in different ways. We have used PHP functions and regular
expressions to create the validation rules.
The easiest and safest way to check whether an email address is well-formed is
to use PHP's filter_var() function.
In the code below, if the e-mail address is not well-formed, then store an error
message:
$email = test_input($_POST["email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
{
$emailErr = "Invalid email format";
}
The code below shows a way to check if a URL address syntax is valid (this
regular expression also allows dashes in the URL). If the URL address syntax is
not valid, then store an error message:
$website = test_input($_POST["website"]);
if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?
=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) {
$websiteErr = "Invalid URL";
}
cd \Apache24\bin
httpd -k install
httpd -k start
...you may well get a warning about the server name. Don't worry
about it. Don't close this window, you will need it again in a minute.
To test it worked type 'http://localhost' into your browser. You
should get a
screen up to the effect that Apache is installed and working.
The version of the module file matters (2_4 in this case). It MUST
match the Apache version installed.
In the same file. Search for the line starting DirectoryIndex. Change
it as follows
memory_limit = 256M
post_max_size = 128M
upload_max_filesize = 128M
You need to specify the extensions required for Moodle. Find the
'Dynamic Extensions' section and change the following lines
(uncomment and add the correct path):
extension=c:/php/ext/php_curl.dll
extension=c:/php/ext/php_gd2.dll
extension=c:/php/ext/php_intl.dll
extension=c:/php/ext/php_mbstring.dll
extension=c:/php/ext/php_mysqli.dll
extension=c:/php/ext/php_openssl.dll
extension=c:/php/ext/php_soap.dll
extension=c:/php/ext/php_xmlrpc.dll
(these are a minimum. You may need others - e.g. LDAP - for specific
functions) ...and save.
Back in the 'cmd' window for Apache, you need to restart it to load
your changes...
httpd -k restart
<?php phpinfo();
To keep this procedure simple, install the WinCache extension but do not
configure it. You will configure and test WinCache in Step 2: Configure
PHP Settings.
To download and install PHP and WinCache
1. Open your browser to Windows for PHP Download Page and download the PHP non-
thread-safe zip package.
2. Download the WinCache extension from the List of Windows Extensions for PHP.
3. Extract all files in the PHP .zip package to a folder of your choice, for
example C:\PHP\ .
4. Extract the WinCache .zip package to the PHP extensions folder (\ext), for
example C:\PHP\ext . The WinCache .zip package contains one file
(Php_wincache.dll).
5. Open Control Panel, click System and Security, click System, and then
click Advanced system settings.
6. In the System Properties window, select the Advanced tab, and then
click Environment Variables.
8. Add the path to your PHP installation folder to the end of the Variable value, for
example ;C:\PHP . Click OK.
9. Open IIS Manager, select the hostname of your computer in the Connections panel,
and then double-click Handler Mappings.
13. In the Executable box, type the full path to Php-cgi.exe, for example C:\PHP\Php-
cgi.exe .
14. In Name, type a name for the module mapping, for example FastCGI.
16. Select the hostname of your computer in the Connections panel, and double-
click Default Document.
17. In the Action panel, click Add. Type Index.php in the Name box, and then click OK.
18. Click Add again. Type Default.php in the Name box, and then click OK.
2. Choose either the php.ini - development or php.ini - production file, and rename
it php.ini.
3. In a text editor, open the php.ini file and added the following line at the end of the
file: extension = php_wincache.dll .
5. Recycle the IIS Application Pools for PHP to pick up the configuration changes.
Unit V
Introduction:
Xml was released in late 90’s. It was created to provide an easy to use and store
self-describing data.
XML tags are not predefined. You must define your own tags.
Syntax:
<tagname> element content</tagname>
The structure of xml tags is as follows:
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
Example:
<student>
<rno>123</rno>
<name>Radha</name>
<age>20</age>
<mobilenumber>7777777</mobilenumber>
<address>
<hno>7-90-456</hno>
<city>hyd<city>
<state>Telangana</state>
</address>
</student>
Here student is a root element. And rno, name, age, mobile number,
address are child elements of student tag.
Elements in XML:
XML elements can be defined as building blocks of an XML.
An element can contain: text, attributes, other elements or a mix of the
above
Each XML document contains one or more elements, the scope of which
are either delimited by start and end tags, or for empty elements, by an
empty-element tag.
Syntax:
<element-name attribute1 attribute2>
....content
</element-name>
Where element-name is the name of the element. The name its case in
the start and end tags must match. Attribute1, attribute2 are attributes of
the element separated by white spaces. An attribute defines a property
of the element. It associates a name with a value, which is a string of
characters. An attribute is written as −name = "value"
Eg: <book category="web">
<title>Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
<name>Radha</name>
<age>20</age>
<mobilenumber>7777777</mobilenumber>
</student>
In the above example course is an attribute of student element.
Comments
XML uses exactly the same syntax as HTML for comments so
that any text that is inserted between <!-- and -->
To add comments in xml file we will use the following syntax:
Syntax:
<!- - comment here - ->
Example:
<!- - This is my xml file - ->
XML declaration
The start of the very first line of every XML document should
elements. The elements, their content (text and attributes) are all
known as nodes.
XML DOM is a standard object model for XML. XML documents
have a hierarchy of informational units called nodes;
Node object can have only one parent node object. This
occupies the position above all the nodes
The parent node can have multiple nodes called
as child nodes. These child nodes can have additional node
called as attribute node
These child nodes in turn can have multiple child nodes. The
text within the nodes is called as text node.
The node objects at the same level are called as siblings.
<Company>
<Employeecategory="technical">
<FirstName>Tanmay</FirstName>
<LastName>Patil</LastName>
<ContactNo>1234567890</ContactNo>
</Employee>
<Employeecategory="non-technical">
<FirstName>Taniya</FirstName>
<LastName>Mishra</LastName>
<ContactNo>1234667898</ContactNo>
</Employee>
</Company>
Advantages of
XML DOM
The following
are the advantages of XML DOM.
XML DOM is language and platform independent.
XML DOM is traversable - Information in XML DOM is
organized in a hierarchy which allows developer to navigate
around the hierarchy looking for specific information.
XML DOM is modifiable - It is dynamic in nature providing the
developer a scope to add, edit, move or remove nodes at any
point on the tree.
Disadvantages of XML DOM
It consumes more memory (if the XML structure is large) as
program written once remains in memory all the time until and
unless removed explicitly.
Due to the extensive usage of memory, its operational speed,
compared to SAX is slower.
1. Elements are the main building blocks of both XML and HTML
documents.
a. Eg: <body>some text</body>
<message>some text</message>
2. Attributes provide extra information about elements.Attributes are
always placed inside the opening tag of an element. Attributes
always come in name/value pairs. The following "img" element
has additional information about a source file:
a. <img src="computer.gif" />
3. Entities are expanded when a document is parsed by an XML
parser.The following entities are predefined in XML:
Entity Character Meaning
1) Internal DTD:
A DTD is referred to as an internal DTD if elements are declared
within the XML files. To refer it as internal DTD, standalone attribute in
XML declaration must be set to yes. This means, the declaration
works independent of an external source.
Syntax
<! DOCTYPE root-element [element-declarations]>
Where root-element is the name of root element and element-
declarations is where you declare the elements.
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>HIIIIIIIIIII</body>
</note>
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 must contain
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"
2) External DTD:
In external DTD elements are declared outside the XML file. They are
accessed by specifying the system attributes which may be either the
legal .dtd file or a valid URL. To refer it as external
DTD, standalone attribute in the XML declaration must be set as no.
This means, declaration includes information from the external source.
Syntax
<!DOCTYPE root-element SYSTEM "file-name">
where file-name is the file with .dtd extension.
Example:
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
DTD Entities
Entities are used to define shortcuts to special characters.
These are the place holders in XML.
Entities can be declared internal or external.
Entities are expanded when a document is parsed by an XML
parser.
Total 5 Character Entities
The following entities are predefined in XML:
There are few special characters or symbols which are not
available to be typed directly from the keyboard. Character
Entities can also be used to display those symbols/special
characters.
There are three types of character entities −
Predefined Character Entities
Numbered Character Entities
Named Character Entities
The following are few character entities:
Entity Character Meaning
< < To display less than symbol
> > To display less than symbol
& & To display ampersand character
" " To display " quotation mark
XML Namespaces
XML Namespace Purpose:
XML Namespaces provide a method to avoid element name conflicts.
Name Conflicts:
In XML, element names are defined by the developer. This often results in
a conflict when trying to mix XML documents from different XML applications.
<h:table>
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table>
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
In the example above, there will be no conflict because the two <table>
elements have different names.
XML Namespaces - The xmlns Attribute: (or document name spaces)
When using prefixes in XML ( i.e. namespace) for the prefix must be
defined.
The namespace is defined by the xmlns attribute in the start tag of an
element.
The namespace declaration has the following syntax.
xmlns: prefix="URI"
Example:
<root>
<h:table xmlns:h="http://www.w3.org/TR/fruits/">
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table xmlns:f="http://www.w3schools.com/furniture/">
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
</root>
Explanation:
In the example above, the xmlns attribute in the <table> tag give the
h: and f: prefixes a qualified namespace.
(OR)
We can declare all the namespaces at one place that is in root element.
<root xmlns:h="http://www.w3.org/TR/html4/"
xmlns:f="http://www.w3schools.com/furniture/">
<h:table>
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table>
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>