MEAN Stack Technologies Unit-1
MEAN Stack Technologies Unit-1
UNIT I: Introduction to Web: Internet and World Wide Web, Domain name service,
Protocols: HTTP, FTP, SMTP. Html5 concepts, CSS3, Anatomy of a web page. XML:
Document type Definition, XML schemas, Document object model, XSLT, DOM and SAX
Approaches.
Web Application
A website is a collection of static files (web pages) such as HTML pages, images, graphics etc.
A Web application is a web site with dynamic functionality on the server. Google, Face
book, Twitter are examples of web applications.
HTTP Methods
HTTP request can be made using a variety of methods, but the ones you will use most often
are Get and Post. The method name tells the server the kind of request that is being made, and
how the rest of the message will be formatted.
HTTP Methods and Descriptions:
Method
Description
Name
Request for communication options that are available on the request/response
OPTIONS
chain.
GET Request to retrieve information from server using a given URI.
Identical to GET except that it does not return a message-body, only the headers
HEAD
and status line.
POST Request for server to accept the entity enclosed in the body of HTTP method.
DELETE Request for the Server to delete the resource.
CONNECT Reserved for use with a proxy that can switch to being a tunnel.
This is same as POST, but POST is used to create, PUT can be used to create as
PUT well as update. It replaces all current representations of the target resource with the
uploaded content.
The first version of the Internet was In the beginning WWW was known
9
known as ARPANET. as NSFNET.
HTTP stands for Hyper Text Transfer Protocol, FTP for File Transfer Protocol, while SMTP
stands for Simple Mail Transfer Protocol. All three are used to transfer information over a
computer network and are an integral part of today’s internet.
Type of band
In-band Out-of-band In-band
transfer
Persistent for
Type of TCP Can use both Persistent Control connection.
Persistent
connection and Non-persistent Non-persistent for
Data Connection
Push Protocol
Type of Protocol Pull Protocol (Mainly) –
(Primarily)
HTTP is stateless. A Stateless protocol implies that the HTTP Web Server does not maintain
which request had originated from which user. Hence, to give customized service to the
user, HTTP uses Cookies.
FTP is Out-of-band, as it uses a separate channel to send data (Data connection), as to send
control information (Control connection).
<acronym> <abbr>
<applet> <object>
<basefont> CSS
<big> CSS
<center> CSS
<dir> <ul>
<font> CSS
<frame>
<frameset>
<noframes>
<isindex>
<tt> CSS
<!DOCTYPE html>
<html>
<head>
<title>This is document title</title>
<style>
h1 {
color: #36CFFF;
}
</style>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
Applications of CSS
As mentioned before, CSS is one of the most widely used style language over the web. I'm going
to list few of them here:
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 it 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.
Audience
This CSS tutorial will help both students as well as professionals who want to make their
websites or personal blogs more attractive.
Prerequisites
You should be familiar with:
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 it 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 a far better look to your HTML page in comparison to HTML attributes.
CSS Versions
Cascading Style Sheets level 1 (CSS1) came out of W3C as a recommendation in December
1996. This version describes the CSS language as well as a simple visual formatting model for
all the HTML tags.
CSS2 became a W3C recommendation in May 1998 and builds on CSS1. This version adds
support for media-specific style sheets e.g. printers and aural devices, downloadable fonts,
element positioning and tables.
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 a 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, border etc.
Value − Values are assigned to properties. For example, color property can have value
either red or #F1F1F1 etc.
You can put CSS Style Rule Syntax as follows −
selector { property: value }
1. Header
Header is the upper (top) part of the webpage. Being the area people see before scrolling the
page in their first seconds on the website, the header is an element of strategic importance. It is
expected from the header to provide the core navigation around the website so that users could
scan it in split seconds and jump to the main pages that can help them. Headers are also referred
to as site menus and positioned as an element of primary navigation in the website layout.
Headers may include a bunch of meaningful layout elements, for example:
basic elements of brand identity, usually a logo
call-to-action button
links to basic categories of website content
links to the social networks
basic contact information (telephone number, e-mail address, etc.)
switcher of the languages in case of the multilingual interface
search field
subscription field or button
links to interaction with the product such as trial version, downloading from the AppStore, etc.
It doesn’t mean that all the mentioned elements should be included in one web page header: in
this case, the header section would be overloaded with information. The more objects attract the
user’s attention, the harder it is to concentrate on the vital ones. On the basis of design tasks,
designers, sometimes together with marketing specialists, decide on the strategically important
options and pick them up from the list or add the others.
What makes a header a vital element contributing to web usability is the fact that it is placed in
the most scannable zone of a web page. Whatever is the scanning pattern users stick to on a
website, it starts from the top part of the page, scanned from left to right for languages using the
same reading and writing pattern. It means that what is placed in the header won’t be missed,
especially the elements placed in its left and right corners. That’s why you will often find the
main CTA button in one of them. What’s more, the power of habit and the idea of external
consistency of user experience should also be taken into account here. For years so far, visitors
have been used to finding core navigation in headers, so mostly, the main question is to decide
what to put into it rather than to use a header or not.
Menus can be organized horizontally or vertically. Some popular types found on diverse
websites are:
Classic horizontal menu: the most common and well-recognized type of menu which presents
the core navigation organized as a horizontal line in the website header, mentioned above
Sidebar menu: quite a classic type, presents a vertical list of options sticking to the left or right
side of the web page
Dropdown menu: a more complex type of menu for content-heavy websites; here, the list of
additional options opens below the primary one when it’s clicked or hovered. Another similar
option is the dropup menu, when the list opens up, not down, but the essence is the same.
Megamenu: that’s the complex expandable menu in which the big list of multiple choices is
presented in a two-dimensional dropdown layout; this approach is effective for cases with a vast
number of options.
Hamburger menu: when the hamburger button (typically marked with three horizontal lines) is
clicked, the menu expands. This option saves space and is often applied to mobile versions of
websites.
8.Breadcrumbs
Breadcrumbs are navigation elements used to support users in a journey around the website:
they get aware of where they are on the website and can get used to the website structure more
easily. So, breadcrumbs present a tool for better wayfinding, yet, they don’t replace the primary
navigation menu; they present the secondary level of navigation and increase website usability in
case it has lots of pages.
Some of the benefits of breadcrumbs are:
increased findability: breadcrumbs give users another touchpoint to the content and help to
catch the structure of the website
fewer clicks needed: with breadcrumbs, website visitors can jump from one level of the
hierarchy to any previous step with no effort and no need to take all the way back
effective use of screen space: crafted well, breadcrumbs take a narrow horizontal line with
plain-looking text elements that don’t need much space
no misinterpretation: breadcrumbs are hardly ever misunderstood by users: the behavior pattern
for them has solidified through years, and people rarely mistake this element for anything else
XML
<?xml version="1.0"?>
<!DOCTYPE address [
<!ELEMENT address (name, email, phone, birthday)>
<!ELEMENT name (first, last)>
<!ELEMENT first (#PCDATA)>
<!ELEMENT last (#PCDATA)>
<!ELEMENT email (#PCDATA)>
<!ELEMENT phone (#PCDATA)>
<!ELEMENT birthday (year, month, day)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT month (#PCDATA)>
<!ELEMENT day (#PCDATA)>
]>
<address>
<name>
<first>Rohit</first>
<last>Sharma</last>
</name>
<email>sharmarohit@gmail.com</email>
<phone>9876543210</phone>
<birthday>
<year>1987</year>
<month>June</month>
<day>23</day>
</birthday>
</address>
XML
<?xml version="1.0"?>
<!DOCTYPE address SYSTEM "address.dtd">
<address>
<name>
<first>Rohit</first>
<last>Sharma</last>
</name>
<email>sharmarohit@gmail.com</email>
<phone>9876543210</phone>
<birthday>
<year>1987</year>
<month>June</month>
<day>23</day>
</birthday>
</address>
address.dtd:
<!ELEMENT address (name, email, phone, birthday)>
<!ELEMENT name (first, last)>
<!ELEMENT first (#PCDATA)>
<!ELEMENT last (#PCDATA)>
<!ELEMENT email (#PCDATA)>
<!ELEMENT phone (#PCDATA)>
<!ELEMENT birthday (year, month, day)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT month (#PCDATA)>
<!ELEMENT day (#PCDATA)>
Output:
Syntax
You need to declare a schema in your XML document as follows −
Example
The following example shows how to use schema −
<?xml version = "1.0" encoding = "UTF-8"?>
<xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema">
<xs:element name = "contact">
<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:schema>
The basic idea behind XML Schemas is that they describe the legitimate format that an XML
document can take.
Elements
As we saw in the XML - Elements chapter, elements are the building blocks of XML document.
An element can be defined within an XSD as follows −
<xs:element name = "x" type = "y"/>
Attributes
Attributes in XSD provide extra information within an element. Attributes
have name and type property as shown below −
<xs:attribute name = "x" type = "y"/>
An XML document is always descriptive. The tree structure is often referred to as XML
Tree and plays an important role to describe any XML document easily.
The tree structure contains root (parent) elements, child elements and so on. By using tree
structure, you can get to know all succeeding branches and sub-branches starting from the root.
The parsing starts at the root, then moves down the first branch to an element, take the first
branch from there, and so on to the leaf nodes.
Example
Following example demonstrates simple XML tree structure −
<?xml version = "1.0"?>
<Company>
<Employee>
<FirstName>Tanmay</FirstName>
<LastName>Patil</LastName>
<ContactNo>1234567890</ContactNo>
<Email>tanmaypatil@xyz.com</Email>
<Address>
<City>Bangalore</City>
<State>Karnataka</State>
<Zip>560212</Zip>
</Address>
</Employee>
</Company>
Following tree structure represents the above XML document −
XML – DOM
The Document Object Model (DOM) is the foundation of XML. XML documents have a
hierarchy of informational units called nodes; DOM is a way of describing those nodes and the
relationships between them.
A DOM document is a collection of nodes or pieces of information organized in a hierarchy.
This hierarchy allows a developer to navigate through the tree looking for specific information.
Because it is based on a hierarchy of information, the DOM is said to be tree based.
The XML DOM, on the other hand, also provides an API that allows a developer to add, edit,
move, or remove nodes in the tree at any point in order to create an application.
Example
The following example (sample.htm) parses an XML document ("address.xml") into an XML
DOM object and then extracts some information from it with JavaScript −
<!DOCTYPE html>
<html>
<body>
<h1>TutorialsPoint DOM example </h1>
<div>
<b>Name:</b> <span id = "name"></span><br>
<b>Company:</b> <span id = "company"></span><br>
<b>Phone:</b> <span id = "phone"></span>
</div>
<script>
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
document.getElementById("name").innerHTML=
xmlDoc.getElementsByTagName("name")[0].childNodes[0].nodeValue;
document.getElementById("company").innerHTML=
xmlDoc.getElementsByTagName("company")[0].childNodes[0].nodeValue;
document.getElementById("phone").innerHTML=
xmlDoc.getElementsByTagName("phone")[0].childNodes[0].nodeValue;
</script>
</body>
</html>
Contents of address.xml are as follows −
<?xml version = "1.0"?>
<contact-info>
<name>Tanmay Patil</name>
<company>TutorialsPoint</company>
<phone>(011) 123-4567</phone>
</contact-info>
Now let us keep these two files sample.htm and address.xml in the same directory /xml and
execute the sample.htm file by opening it in any browser. This should produce the following
output.
Here, you can see how each of the child nodes is extracted to display their values.
XSL stands for EXtensible Stylesheet Language. XSLT is for Transformation of XML document
to other formats.
What is XSLT
Before XSLT, first we should learn about XSL. XSL stands for EXtensible Stylesheet Language.
It is a styling language for XML just like CSS is a styling language for HTML.
XSLT stands for XSL Transformation. It is used to transform XML documents into other
formats (like transforming XML into HTML).
What is XSL
In HTML documents, tags are predefined but in XML documents, tags are not predefined. World
Wide Web Consortium (W3C) developed XSL to understand and style an XML document,
which can act as XML based Stylesheet Language.
Image representation:
o XSLT provides an easy way to merge XML data into presentation because it applies user defined
transformations to an XML document and the output can be HTML, XML, or any other
structured document.
o XSLT provides Xpath to locate elements/attribute within an XML document. So it is more
convenient way to traverse an XML document rather than a traditional way, by using scripting
language.
o XSLT is template based. So it is more resilient to changes in documents than low level DOM and
SAX.
o By using XML and XSLT, the application UI script will look clean and will be easier to maintain.
o XSLT templates are based on XPath pattern which is very powerful in terms of performance to
process the XML document.
o XSLT can be used as a validation language as it uses tree-pattern-matching approach.
o You can change the output simply modifying the transformations in XSL files.
Now, the package that provides linkage applications for clients that work with an XML
document is called an XML Parser. It was planned to read the XML documents. An XML
Parser was created for doing programs to use XML.
SAX Parser
SAX represents a simple API for XML and a SAX API is implemented by SAX Parser. This
API was called event-based API which provides interfaces on handlers. There are four handler
interfaces. ContentHandler, DTDHandler, EntityResolver, and ErrorHandler interface. It does
not create any internal structure rather it takes the occurrences of components of an input
document as events, and then it tells the client what it reads as it reads through the input
document. It is suitable for large XML files because it doesn’t require loading the whole XML
file.
It is called a Simple API for XML Parsing. It is called as Document Object Model.
SAX Parser is slower than DOM Parser. DOM Parser is faster than SAX Parser.
Best for the larger sizes of files. Best for the smaller size of files.
The internal structure can not be created by The internal structure can be created by DOM
In the SAX parser backward navigation is not In DOM parser backward and forward search
possible. is possible