WT Unit 2
WT Unit 2
Web Technology
(ACSE-0505)
Unit: 2
Introduce Cascading Style Sheets (CSS) for applying visual styles to web
pages. Cover topics such as selectors, properties, box model, layout
techniques, and responsive design.
ACSE
0505
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
3 2 2 1 1 1 1 1 3 3 2 3
1
3 2 3 1 3 2 2 1 3 3 3 3
2
3 2 3 2 3 2 2 2 3 3 2 3
3
3 3 3 2 3 2 2 2 3 3 2 3
4
3 3 3 2 3 2 2 2 3 3 2 3
5
Average 2.4 2.8 1.6 2.6 1.8 1.8 1.6 3 3 2.2 3
3
1 3 3 2 3
2 3 3 3 2
3 3 3 2 2
4 3 2 3 2
5 3 2 2 2
• PEO3: Able to inculcate professional and social ethics, team work and
leadership serving the society.
To begin learning HTML and XML, there are a few helpful prerequisites.
HTML Objectives:
XML Objectives:
2. HTML Tag: The HTML tag (<html>) serves as the root element of the HTML
document. It encapsulates the entire content of the page.
3. Head Section: The <head> element contains metadata and other non-visible
information about the document. It does not represent the visible content of the page.
Some common elements within the <head> section include:
4. Body Section: The <body> element represents the main content of the web page. It
contains all the visible elements that are displayed in the browser window. Common elements
within the <body> section include:
<header>: Represents the introductory content at the top of the page, often containing logos,
navigation menus, or headings.
<nav>: Represents a section containing navigation links.
<main>: Represents the main content area of the page.
<article>: Represents a self-contained composition within a document, such as a blog post or
a news article.
<section>: Represents a standalone section within a document, typically grouped by a
common theme.
<aside>: Represents content that is tangentially related to the main content, such as sidebars
or pull quotes.
<footer>: Represents the footer section at the bottom of the page, often containing copyright
information, links, etc.
5. HTML Elements: Within the body section, you can use various HTML elements to
structure and format your content.
HTML5 introduced several new semantic elements that provide a more structured and
meaningful way to represent content on web pages.
<main>: Represents the main content of a document. It should be unique and not
nested within other structural elements like <article>, <section>, or <aside>.
<aside>: Represents a section of content that is tangentially related to the main content,
such as sidebars, pull quotes, or advertising.
<figure> and <figcaption>: <figure> represents self-contained content like images, videos,
or illustrations, while <figcaption> provides a caption or description for the content within
the <figure> element.
<time>: Represents a specific date, time, or duration. It can be used to mark up events,
publication dates, or timestamps.
<mark>: Highlights a portion of text to indicate its relevance or importance within the
context.
Tables in HTML5 are used to present tabular data, where information is organized in rows
and columns. HTML5 introduced new attributes and elements to enhance the accessibility
and semantic structure of tables.
Table Structure:
<th>: Represents a table header cell. It is used to define the headers of columns or rows.
<tr>: Defines a table row.
<th scope="">: This attribute specifies the scope of a header cell. It can take values like
"row", "col", "rowgroup", or "colgroup" to indicate the scope of the header.
<td>: Represents a table data cell. It is used to define the content within a table row.
Table Captions:
<caption>: Defines a caption for the table. It should be placed immediately after the
opening <table> tag.
Table Spanning:
colspan attribute: Specifies the number of columns a table cell should span.
rowspan attribute: Specifies the number of rows a table cell should span.
<td headers="">: Specifies the ID(s) of the header cell(s) that apply to a data cell. This
association helps assistive technologies understand the relationships between headers and
data cells.
HTML lists allow web developers to group a set of related items in lists.
•Item
•Item
•Item
•Item
1.First item
2.Second item
3.Third item
4.Fourth item
Try it Yours
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
3: Which attribute is used to specify the URL of an image in the <img> tag?
a) src
b) alt
c) href
d) link
Answer: a) src
December 13, 2024 Rajat Kumar WT UNIT 2 38
Daily Quiz
5: Which attribute is used to provide alternative text for an image in the <img> tag?
a) src
b) alt
c) title
d) link
Answer: b) alt
_self - Default. Opens the document in the same window/tab as it was clicked
_blank - Opens the document in a new window or tab
_parent - Opens the document in the parent frame
_top - Opens the document in the full body of the window
Both examples above are using an absolute URL (a full web address) in the href
attribute.
A local link (a link to a page within the same website) is specified with a relative
URL (without the "https://www" part):
<h2>Absolute URLs</h2>
<p><a href="https://www.niet.co.in/">NIET</a></p>
<h2>Relative URLs</h2>
<p><a href="html_images.asp">HTML Images</a></p>
• Basics of HTML
• Concepts of HTML Tags
• Concepts of Tables
• Concepts of HTML Lists
• Concepts of HTML Links
• Concepts of HTML Images
An HTML form is used to collect user input. The user input is most often sent to a server
for processing.
The HTML <form> element is used to create an HTML form for user input:
<form>
.
form elements
.
</form>
The <form> element is a container for different types of input elements, such as: text
fields, checkboxes, radio buttons, submit buttons, etc.
Type Description
<input type="text"> Displays a single-line text input field
<input type="radio"> Displays a radio button (for selecting
one of many choices)
The <input type="text"> defines a single-line input field for text input.
<form>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname">
</form>
• The <label> element is useful for screen-reader users, because the screen-reader
will read out loud the label when the user focuses on the input element.
• The <label> element also helps users who have difficulty clicking on very small
regions (such as radio buttons or checkboxes) - because when the user clicks the
text within the <label> element, it toggles the radio button/checkbox.
• The for attribute of the <label> tag should be equal to the id attribute of the
<input> element to bind them together.
<form>
<input type="checkbox" id="vehicle1" name="vehicle1" value="Bike">
<label for="vehicle1"> I have a bike</label><br>
<input type="checkbox" id="vehicle2" name="vehicle2" value="Car">
<label for="vehicle2"> I have a car</label><br>
<input type="checkbox" id="vehicle3" name="vehicle3" value="Boat">
<label for="vehicle3"> I have a boat</label>
</form>
• The <input type="submit"> defines a button for submitting the form data to a form-
handler.
• The form-handler is typically a file on the server with a script for processing input data.
• The form-handler is specified in the form's action attribute.
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
</form>
• The <input type="submit"> defines a button for submitting the form data to a form-
handler.
• The form-handler is typically a file on the server with a script for processing input data.
• The form-handler is specified in the form's action attribute.
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
</form>
Notice that each input field must have a name attribute to be submitted.
If the name attribute is omitted, the value of the input field will not be sent at all.
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" value="John"><br><br>
<input type="submit" value="Submit">
</form>
<input type="number">
<input type="button"> <input type="password">
<input type="checkbox"> <input type="radio">
<input type="color"> <input type="range">
<input type="date"> <input type="reset">
<input type="datetime-local"> <input type="search">
<input type="email"> <input type="submit">
<input type="file"> <input type="tel">
<input type="hidden"> <input type="text">
<input type="image"> <input type="time">
<input type="month"> <input type="url">
<input type="week">
<form>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe">
</form>
1: Which attribute is used to specify the URL that a link should navigate to?
a) src
b) link
c) href
d) url Answer: c) href
4: Which attribute is used to specify the HTTP method for submitting a form?
a) action
b) method
c) submit
d) type
Answer: b) method
XML, which stands for Extensible Markup Language, is a versatile and widely used
markup language designed for storing and exchanging structured data. It provides a
flexible way to describe and organize information in a hierarchical format.
XML uses tags to define elements within a document, similar to HTML. However,
unlike HTML, which is primarily used for structuring web content, XML is not limited
to any specific domain. It is a generic markup language that can be used for a variety
of purposes, such as storing data, configuring settings, representing document
structures, and more.
One of the key strengths of XML is its ability to define custom tags and document
structures. This flexibility allows XML to adapt to different data formats and industry-
specific needs. XML documents are typically human-readable and self-descriptive,
making them easy to understand and interpret.
XML Definition
• Tags: XML documents are made up of elements enclosed within start and end tags.
Tags are used to define the structure and hierarchy of the document's content.
• Start tags begin with a less-than symbol (<), followed by the element name, and end
with a greater-than symbol (>).
• End tags have a similar syntax, but also include a forward slash (/) before the element
name.
Elements: Elements are the building blocks of an XML document. They represent
individual pieces of information within the document. Each element has a start tag, an end
tag, and may contain nested elements and/or text content.
Attributes: Attributes provide additional information about an element. They are placed
within the start tag of an element and consist of a name-value pair. Attribute values are
enclosed in quotation marks.
XML namespaces are used to avoid naming conflicts when different XML vocabularies or
elements with the same name are combined. They provide a way to uniquely identify and
differentiate elements and attributes in an XML document.
Namespace declarations are typically added to the root element of an XML document or to
individual elements. They are declared using the xmlns attribute, where the namespace
prefix is associated with its corresponding URI. The xmlns attribute without a prefix
specifies the default namespace for elements that don't have a namespace prefix explicitly
defined.
In this example, two namespaces are declared: ns1 and ns2. The prefixes ns1 and ns2 are
used to qualify the elements element1 and element2, respectively. By using different
prefixes, the elements can be distinguished even if they have the same local name.
Namespace prefixes are not mandatory and can be omitted, as shown in the
following example:
In this case, the default namespace is set using xmlns without a prefix. The
element element1 is associated with the default namespace, while element2 uses
the ns2 prefix to indicate its namespace.
All modern browsers have a built-in XMLHttpRequest object to request data from a server.
The XMLHttpRequest object can be used to request data from a web server.
The XMLHttpRequest object is a developers dream, because you can:
XML Validation
• A well formed XML document can be validated against DTD or Schema.
• It is very necessary to know about valid XML document before knowing XML
validation.
Example Of XML
<?xml version="1.0"?>
<employee>
<firstname>vimal</firstname>
<lastname>jaiswal</lastname>
<address>Gaziabad</address>
<email>[email protected]</email>
</employee>
2: Which character is used to indicate the start and end of an XML element?
a) <
b) >
c) /
d) &
Answer: a) <
5: Which symbol is used to separate the namespace prefix and element name in XML?
a) :
b) .
c) /
d) _
Answer: a) :
• A W3C standard
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.statu
s == 200) {
myFunction(this); } }
function myFunction(xml) {
var xmlDoc = xml.responseXML;
document.getElementById("demo").innerHTML =
xmlDoc.getElementsByTagName("title")
[0].childNodes[0].nodeValue;
}
</script>
</body>
</html>
• Basics of XML
• XML syntax
• XML Document
• XML Namespace
• XML Validation
• Basics of Document Object Model.
XML Processors
• Any program that can read and process XML documents is known
as an XML processor.
• An XML processor reads the XML file and turns it into in-memory
structures that the rest of the program can access.
• XML Parsers
• The XML Parser is designed to read the XML and create a way
for programs to use XML.
• XML parser validates the document and check that the document
is well formatted.
• XML Parsers(cont..)
Disadvantages
• It consumes more memory because the whole XML document needs to
loaded into memory.
• Clients does not know what methods to call, they just overrides the methods
of the API and place his own code inside method.
5: Which type of XML parser reads the entire XML document into memory before
processing?
a) Event-based parser
b) Tree-based parser
c) SAX parser
d) DOM parser
Answer: d) DOM parser
6: Which type of XML parser processes XML documents sequentially and triggers events as
it encounters different elements?
a) Event-based parser
b) Tree-based parser
c) SAX parser
d) DOM parser
Answer: c) SAX parser
December 13, 2024 Rajat Kumar WT UNIT 2 87
Introduction XML(cont..)
Advantages
• It is simple and memory efficient.
Disadvantages
• It is event-based so its API is less intuitive.
• Clients never know the full information because the data is broken into
pieces.
XML documents are well-formed when they adhere to specific syntax rules, such as
properly nested tags and correct use of attributes. Additionally, XML documents can be
validated against Document Type Definitions (DTDs) or XML Schemas to ensure their
structure and content integrity.
XML is often used in conjunction with other technologies, such as XSLT (eXtensible
Stylesheet Language Transformations) for transforming XML data into different
formats, and XPath for querying and selecting specific parts of an XML document.
Often a plus (+) or minus sign (-) to the left of the elements can be clicked to expand
or collapse the element structure.
To view raw XML source, try to select "View Page Source" or "View Source" from
the browser menu.
Note: In Safari 5 (and earlier), only the element text will be displayed. To view the
raw XML, you must right click the page and select "View Source".
The XMLHttpRequest object can be used to request data from a web server.
The XMLHttpRequest object is a developers dream, because you can:
•Update a web page without reloading the page
•Request data from a server - after the page has loaded
•Receive data from a server - after the page has loaded
•Send data to a server - in the background
When you type a character in the input field below, an XMLHttpRequest is sent to
the server, and some name suggestions are returned (from the server):
Sending an XMLHttpRequest:
A common JavaScript syntax for using the XMLHttpRequest object looks much like
this:
/bookstore/book[last()] Selects the last book element that is the child of the
bookstore element
/bookstore/book[last()-1] Selects the last but one book element that is the child of
the bookstore element
/bookstore/book[position()<3] Selects the first two book elements that are children of
the bookstore element
//title[@lang='en'] Selects all the title elements that have a "lang" attribute
with a value of "en"
In the table below we have listed some XPath expressions and the result of the expressions:
/bookstore/ Selects all the title elements of the book elements of the
book[price>35.00]/title bookstore element that have a price element with a value
greater than 35.00
XSLT is far more sophisticated than CSS. With XSLT you can add/remove
elements and attributes to or from the output file. You can also rearrange and sort
elements, perform tests and make decisions about which elements to hide and
display, and a lot more.
3: Which XPath expression selects all elements with a specific tag name?
a) //elementName
b) /elementName
c) //*elementName
d) elementName
Answer: a) //elementName
December 13, 2024 Rajat Kumar WT UNIT 2 102
Daily Quiz
4: What does XSLT stand for?
a) XML Style Language Transformation
b) eXtensible Stylesheet Language Transformation
c) XML Structure Language Transformation
d) eXtensible Style Language Translator
Answer: b) eXtensible Stylesheet Language Transformation
6: Which element is used in XSLT to match and select nodes for transformation?
a) <template>
b) <output>
c) <apply-templates>
d) <stylesheet>
Answer: c) <apply-templates>
December 13, 2024 Rajat Kumar WT UNIT 2 103
XML :XQuery
for $x in doc("books.xml")/bookstore/book
where $x/price>30
order by $x/title
return $x/title
XLink Syntax
In HTML, the <a> element defines a hyperlink. However, this is not how it works in
XML. In XML documents, you can use whatever element names you want - therefore
it is impossible for browsers to predict what link elements will be called in XML
documents.
Below is a simple example of how to use XLink to create links in an XML document:
<homepages xmlns:xlink="http://www.w3.org/1999/xlink">
<homepage xlink:type="simple" xlink:href="https://www.w3schools.com">Visit
W3Schools</homepage>
<homepage xlink:type="simple" xlink:href="http://www.w3.org">Visit W3C</homepage>
</homepages>
Example explained:
The XLink namespace is declared at the top of the document
(xmlns:xlink="http://www.w3.org/1999/xlink")
The xlink:type="simple" creates a simple "HTML-like" link
The xlink:href attribute specifies the URL to link to (in this case - an image)
The xlink:show="new" specifies that the link should open in a new window
6: Which element is used in XLink to define the start and end points of a link?
a) <link>
b) <source>
c) <locator>
d) <arc>
Answer: d) <arc>
December 13, 2024 Rajat Kumar WT UNIT 2 112
XML :Validator
XML files are plain text files just like HTML files.
XML can easily be stored and generated by a standard web server.
XML DTD
• Actually DTD and XML schema both are used to form a well formed XML
document.
<address>
<name>Devendra Kumar</name>
<company>NIET</company>
<phone>(011) 123-4567</phone>
</address>
External DTD
address.dtd
XML schema
• Syntax
<xs:schema xmlns:xs="http://www.org/2001/XMLSchema">
• Simple Type
• Complex Type
• Global Types
<xs:element
name="Address"><xs:complexType><xs:sequence>
<xs:element name="name" type="xs:string" /> <xs:element
name="company" type="xs:string" /> <xs:element
name="phone" type="xs:int" /> </xs:sequence>
</xs:complexType></xs:element>
<xs:element name="Address1">
<xs:complexType> <xs:complexType>
<xs:sequence>
<xs:sequence> <xs:element name="address"
<xs:element name="address" type="AddressType" />
type="AddressType" /> <xs:element name="phone2"
<xs:element name="phone1" type="xs:int" />
type="xs:int" /> </xs:sequence>
</xs:complexType></xs:element
</xs:sequence> >
</xs:complexType></xs:element
> <xs:element
name="Address2">
XML Validator
XML Schema
XML DTDs
With their examples
1.Which language is used to create the structure and content of web pages?
a) HTML
b) XML
c) CSS
d) JavaScript
3.Which HTML tag is used to define the main heading of a web page?
a) <h1>
b) <title>
c) <head>
d) <body>
6. Which XML tag is used to define the root element of an XML document?
a) <html>
b) <root>
c) <body>
d) <xml>
a. <scroll>
b. <marquee>
c. <ciruler>
d. <tab>
a. font
b. class
c. styles
d. style
10. A CSS combinator is the one which explains the relationship between the selectors.
a. True
b. False
11. Which is used about text data that should not be parsed by the XML parser
a. CDATA
b. PCDATA
c. None of the above
To add a plain color background to your web page, use which of the
following?
a) <body bgcolor= “36,24,35”>
b) <body color= “# FF000”>
c) <body bgcolor= “# FF000”>
d) All of the above
• Ivan Bayross,” HTML, DHTML, Java Script, Perl & CGI”, BPB
Publication