Web Technology
Web Technology
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
Domain Name:
To identify a computer resource on internet, each computer is assigned
with an IP address. It is a series of numbers that identify a particular
computer on the internet. A typical IP address looks like this: 66.249.66.1.
Now an IP address like this is quite difficult to remember. Domain names
were invented to solve this problem.
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
HTML markup tags are usually called HTML tags.
HTML tags are keywords (tag names) surrounded by angle
brackets like <html>
HTML tags normally come in pairs like <html> and </html>.
The first tag in a pair is the start tag, the second tag is the end
tag. The end tag is written like the start tag, with a slash before
the tag name.
Start and end tags are also called opening tags and closing
tags.
In HTML, tags are paired tags and unpaired tags. Paired tags
have opening tag and ending tag. Unpaired tags doesn’t have
end tag.
HTML tags are not case sensitive, <b> means the same as <B>.
In HTML there are both logical tags and physical tags. Logical tags are designed to
describe (to the browser) the enclosed text's meaning. Physical tags on the other
hand provide specific instructions on how to display the text they enclose.
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.
<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.
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 Table Cell Padding and Spacing
The cell-padding and cell-spacing attributes are used to adjust white
space inside a table.
Cell-padding adjust the white space between table cell border
and its content.
Cell-spacing adjust the white space between table cells.
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
rule of a tag and apply to all the occurrences of that tag. So
less code means faster download times.
Easy maintenance - To make a global change, simply
change the style, and all elements in all the web pages will
be updated automatically.
Superior styles to HTML - CSS has a much wider array of
attributes than HTML so you can give far better look to your
HTML page in comparison of HTML attributes.
Multiple Device Compatibility - Style sheets allow content
to be optimized for more than one type of device. By using
the same HTML document, different versions of a website
can be presented for handheld devices such as PDAs and cell
phones or for printing.
Global web standards - Now HTML attributes are being
deprecated and it is being recommended to use CSS. So it’s
a good idea to start using CSS in all the HTML pages to
make them compatible to future browsers.
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
properties. They could be color or border etc.
Value: Values are assigned to properties. For example color
property can have value either red or #F1F1F1 etc.
Basic Structure of a Style
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
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.
<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
your documents. The most important attributes of the DIV element
are:
style
class
id
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
incorporates the CSS2 standard with some changes and
improvements. A key change is the division of standard into separate
modules, which makes it easier to learn and understand. CSS3 permits
to pick out additional hypertext markup language tags and outline
however they're displayed on an online browser. CSS3 is divided into
several separate documents called "modules". Some of the most
important CSS3 modules are: –
Selectors
Box Model
Backgrounds and Borders
Text Effects
2D/3D Transformations
Animations
Multiple Column Layout
User Interface
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
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.
If the padding is 0, then the padding-box is exactly the same
size as the content-box, and the content limit coincides with the
padding limit.
If the border-width is 0, the border-box is the same size as
the padding-box, and the border limit coincides with the
padding limit.
If both the padding and the border-width are 0, then all the
three boxes (the content-box, the padding-box, and the border-
box) have the same size, and the content limit, the padding
limit, and the border limit all coincide.
Ex:Specify how far the background should extend within an element:
div {
border: 10px dotted black;
padding: 15px;
background: lightblue;
background-clip: padding-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-wrap: normal | break-word | initial;
Values:
Normal: break words only at allowed break points.
Break-word: allows unbreakable words to be broken
Initial: sets this property to its default value.
Ex: Allow long words to be able to break and wrap onto the next line:
div {
word-wrap: break-word;
}
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.
scale – given a width and height, the element will increase or
decrease its size. There are also scaleX and scaleY functions
that get only one parameter and scale the element only in
one axis.
skew – given x degree and y degree parameters, the element
will turn in the given angles first in the x-axis and then in the
y-axis. There are also skewX and skewY functions that get
only one parameter and skew the element only in one axis.
matrix – given six a-f parameters apply the transformation
matrix [a b c d e f] on the element.
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)
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.
Browser Compatible: The biggest advantages to a JavaScript having a ability to
support all modern browser and produce the same result.
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.
Number – Any numeric value whether an integer number or float number.
Eg: 12 , 3.1415
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
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.
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
Elements need not be of the same type
Elements can be primitive values or object references (possibly functions or other
arrays)
Has dynamic length
Index of array runs from 0 to N-1.
Eg: Created via an Array literal:
1. var a3 = [“7”, 1, new Date(), false];
Eg: create an array via array object of N elements, you can write:
var myArray = new Array(N);
Eg: Can store values of different types
var a1 = new Array( );
a1[0] = 27; a1[45] = "Hello";
var Car = new Array(3);
Car[0] = "Ford";
Car[1] = "Toyota";
Car[2] = "Honda";
var Car2 = new Array("Ford", "Toyota", "Honda");
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.
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)
{
Statement or block to execute
}
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.
</head>
<body>
<p>Click the following button to call the
function</p>
<form>
<input type="button" onclick="sayHello()"
value="Say Hello">
</form>
</body>
</html>
Objects in JavaScript:
In JavaScript, an object is defined as
an "unordered collection of properties each
of which contains a primitive value, object,
or function ".
The objects are described by properties and
their behavior is defined by methods. An
object is collection of these properties and
methods which can be defined and altered and
retrieved by the user.
JavaScript objects are dynamic in nature,
properties and methods can be added and
deleted by the user. Each property or method
is identified by the name that is mapped to
a value.
<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
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;
echo "<h2>" . $txt1 . "</h2>";
echo "Study PHP at " . $txt2 . "<br>";
echo $x + $y;
?>
The PHP print Statement
The print statement can be used with or without parentheses like
print or print( ) to display text.
The following example shows how to output text with
the print command (notice that the text can contain HTML markup):
Example
<?php
print "<h2>PHP is Fun!</h2>";
print "Hello world!<br>";
print "I'm about to learn PHP!";
?>
Display Variables: The following example shows how to output text
and variables with the print statement:
Example
<?php
$txt1 = "Learn PHP";
$txt2 = "W3Schools.com";
$x = 5;
$y = 4;
</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>
The output could be something like this:
Welcome John
Your email address is [email protected]
The same result could also be achieved using the HTTP GET method:
Example
<html>
<body>
</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.
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.
Email address validation
We need to check if the email field is empty. If it is empty, an error
message will be displayed. This message will be stored in the variable
$email_error. We have used a PHP function called filter_var() to validate
the email address entered by the user.
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, or Extensible Markup Language, is a markup language that is
used to create our own tags. It was created by the World Wide Web
Consortium (W3C) to overcome the limitations of HTML, the Hypertext
Markup Language is the basis for all Web pages.
XML is widely used in the era of web development. It is also used to simplify data
storage and data sharing.
XML is based on SGML -- Standard Generalized Markup
Language.
XML is designed to store and transport data.
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.
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>
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
contain the XML declaration.
This identifies the document to be a XML document and
defines the version of XML.
The XML declaration is stated in a special tag starts <? and
ends with ?>.
Inside the tag, the element is named ‘xml’ to denote that it is a
part of the XML specification.
To define XML version we will use version attribute and that is
assigned the version number as its value. The version number
is 1.0. that is as follows,
<?xml version=“1.0”?>
The XML declaration may include an attribute called
‘standalone’ to specify if that document uses other documents.
It has two values either ‘yes’ or ‘no’.
<?xml version=“1.0”? standalone=“yes”>
XML Document Object Model (DOM)
The Document Object Model (DOM) is a W3C standard. The
Document Object Model (DOM) is an application programming
interface (API) for HTML and XML documents. It defines the
logical structure of documents and the way a document is
accessed and manipulated.
The DOM defines a standard for accessing and manipulating
documents: "The W3C Document Object Model (DOM) is a
platform and language-neutral interface that allows programs and
scripts to dynamically access and update the content, structure,
and style of a document."
The XML DOM defines a standard way for accessing and
manipulating XML documents. It presents an XML document as a
tree-structure.
We can access all elements through the DOM tree.
We can modify or delete their content and also create new
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.
XML DTD (Data Type Definition):
The XML Document Type Definition (DTD) is a way to describe
XML language precisely.
It defines the legal building blocks of an XML document. It is
used to define document structure with a list of legal elements
and attributes.
DTDs check vocabulary and validity of the structure of XML
documents against grammatical rules of appropriate XML
language.
An XML DTD can be either specified inside the document, or it
can be kept in a separate document and then liked separately.
Its main purpose is to define the structure of an XML
document. It contains a list of legal elements and define the
structure with the help of them.
A "Valid" XML document is a "Well Formed" XML document,
which also conforms to the rules of a DTD:
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
< < To display less than symbol
> > To display less than symbol
& & To display ampersand character
" " To display " quotation mark
' ' To display ' apostrophe (single quote)
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>
<body>Don't forget me this weekend!</body>
</note>
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
' ' To display ' apostrophe (single quote)
Example:
<group>MPCS & MECS & MSCS</group>
Output:
<group>MPCS & MECS & MSCS</group>
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.
(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>