Unit 5 Web
Unit 5 Web
Syllabus:
XML: defining data for web applications, basic XML, document
type definition, presenting XML, document object model. Web
Services
Applications of XML:
There are countless number of application exist that use XML, here area few
examples of the current plat form and applications that are making of this
technology
Cell phones, Fine converters, etc.,
Cell phones
XML data is sent some cell phones. The data is then formatted by the
specification of the cell phone software designer to display text or images
and even play sounds.
File converters
Many applications have been written to convert existing Documents into the
xml standard. An example is a pdf to xml converter
Noise XML
Converts xml documents into an audio format so that you can listen to an
xml documents.
Features and Advantages of XML
XML is widely used in the era of web development. It is also used to simplify data
storage and data sharing.
The main features or advantages of XML are given below.
1) XML separates data from HTML
If you need to display dynamic data in your HTML document, it will take a lot of
work to edit the HTML each time the data changes.
With XML, data can be stored in separate XML files. This way you can focus on
using HTML/CSS for display and layout, and be sure that changes in the underlying
data will not require any changes to the HTML.
With a few lines of JavaScript code, you can read an external XML file and update
the data content of your web page.
2) XML simplifies data sharing
In the real world, computer systems and databases contain data in incompatible
formats.
XML data is stored in plain text format. This provides a software- and hardware-
independent way of storing data.
This makes it much easier to create data that can be shared by different
applications.
3) XML simplifies data transport
One of the most time-consuming challenges for developers is to exchange data
between incompatible systems over the Internet.
Exchanging data as XML greatly reduces this complexity, since the data can be
read by different incompatible applications.
2
Prepared by [Link],[Link](CSE), Lecturer in computer science, SVDC,Titupati
4) XML simplifies Platform change
Upgrading to new systems (hardware or software platforms), is always time
consuming. Large amounts of data must be converted and incompatible data is
often lost.
XML data is stored in text format. This makes it easier to expand or upgrade to
new operating systems, new applications, or new browsers, without losing data.
5) XML increases data availability
Different applications can access your data, not only in HTML pages, but also from
XML data sources.
With XML, your data can be available to all kinds of "reading machines" (Handheld
computers, voice machines, news feeds, etc), and make it more available for blind
people, or people with other disabilities.
6) XML can be used to create new internet languages
A lot of new Internet languages are created with XML.
Here are some examples:
o XHTML
o WSDL for describing available web services
o WAP and WML as markup languages for handheld devices
o RSS languages for news feeds
o RDF and OWL for describing resources and ontology
o SMIL for describing multimedia for the web
Differences between HTML and XML
The differences between HTML and XML
HTML XML
It stands for Hyper text markup It stands for Extensible markup
language language
It contain predefined tags It does not contain predefined
tags, User needs to create his own
tags
HTML is not case sensitive XML is case sensitive
Some tags require no closing tags All tags must be closed
It is used to develop static web It is used to develop Dynamic web
pages pages
HTML is an application of SGML XML is subset of SGML
HTML document no need of root XML document needs of root
element element
HTML Supports links and creating XML Supports links and creating
links is very ease. links is complex.
HTML Doesn’t Require CSS for its XML Requires CSS or XSL or DOM
display for its display
If HTML Code is not written If XML Code is not written
properly, it does not raise any properly, it raises error
error
3
Prepared by [Link],[Link](CSE), Lecturer in computer science, SVDC,Titupati
HTML Document extension XML Document Extension is .XML
is .HTML
HTML is Designed for XML is designed for carry data
representation ordering the
product forms
Retrieve online information via It is designed to the self descript.
hyperlinks at the click of a button
5
Prepared by [Link],[Link](CSE), Lecturer in computer science, SVDC,Titupati
If document contains XML declaration, then it strictly needs to be the first
statement of the XML document.
The XML declaration strictly needs be the first statement in the XML
document.
An HTTP protocol can override the value of encoding that you put in the XML
declaration.
Tags and Elements
An XML file is structured by several XML-elements, also called XML-nodes or XML-
tags. The names of XML-elements are enclosed in triangular brackets < > as
shown below −
<element>
Syntax Rules for Tags and Elements
Element Syntax − Each XML-element needs to be closed either with start or with
end elements as shown below −
<element>....</element>
Or in simple-cases, just this way −
<element/>
Nesting of Elements − An XML-element can contain multiple XML-elements as
its children, but the children elements must not overlap. I.e., an end tag of an
element must have the same name as that of the most recent unmatched start
tag.
The Following example shows incorrect nested tags −
<?Xml version = "1.0"?>
<contact-info>
<company>tutorialspoint
<contact-info>
</company>
The Following example shows correct nested tags −
<?Xml version = "1.0"?>
<contact-info>
<company>tutorialspoint</company>
<contact-info>
Root Element − An XML document can have only one root element. For
example, following is not a correct XML document, because both
the x and y elements occur at the top level without a root element −
<x>...</x>
<y>...</y>
The Following example shows a correctly formed XML document −
<root>
<x>...</x>
<y>...</y>
</root>
Case Sensitivity − The names of XML-elements are case-sensitive. That means
the name of the start and the end elements need to be exactly in the same case.
6
Prepared by [Link],[Link](CSE), Lecturer in computer science, SVDC,Titupati
For example, <contact-info> is different from <Contact-Info>
XML Attributes
An attribute specifies a single property for the element, using a name/value pair.
An XML-element can have one or more attributes. For example −
<a href = "[Link]
Here href is the attribute name and [Link] is attribute
value.
Syntax Rules for XML Attributes
Attribute names in XML (unlike HTML) are case sensitive. That
is, HREF and href are considered two different XML attributes.
Same attribute cannot have two values in a syntax. The following example
shows incorrect syntax because the attribute b is specified twice
−
<a b = "x" c = "y" b = "z">....</a>
Attribute names are defined without quotation marks, whereas attribute
values must always appear in quotation marks. Following example
demonstrates incorrect xml syntax
−
<a b = x>....</a>
In the above syntax, the attribute value is not defined in quotation marks.
XML References
References usually allow you to add or include additional text or markup in an
XML document. References always begin with the symbol "&" which is a reserved
character and end with the symbol ";". XML has two types of references −
Entity References − An entity reference contains a name between the
start and the end delimiters. For example & where amp is name.
The name refers to a predefined string of text and/or markup.
Character References − These contain references, such as A,
contains a hash mark (“#”) followed by a number. The number always
refers to the Unicode code of a character. In this case, 65 refers to alphabet
"A".
XML Text
The names of XML-elements and XML-attributes are case-sensitive, which means
the name of start and end elements need to be written in the same case. To avoid
character encoding problems, all XML files should be saved as Unicode UTF-8 or
UTF-16 files.
Whitespace characters like blanks, tabs and line-breaks between XML-elements
and between the XML-attributes will be ignored.
7
Prepared by [Link],[Link](CSE), Lecturer in computer science, SVDC,Titupati
Although browsers are primarily intended to use the World Wide Web, they
can also be used to access information provided by web servers in private
networks or files in file systems.
The most popular web browsers are Chrome, Safari, Opera and Firefox.
Features of Web Browsers
Available web browsers range in features from minimal, text-based user
interfaces with bare-bones support for HTML to rich user interfaces
supporting a wide variety of file formats and protocols.
Browsers which include additional components to support e-
ail, Usenet news, and Internet Relay Chat (IRC), are sometimes referred to as
"Internet suites" rather than merely "web browsers.
All major web browsers allow the user to open multiple information resources
at the same time, either in different browser windows or in different tabs of
the same window.
Major browsers also include pop-up blockers to prevent unwanted windows
from "popping up" without the user's consent.
Most web browsers can display a list of web pages that the user
has bookmarked so that the user can quickly return to them. Bookmarks are
also called "Favorites" in Internet Explorer.
In addition, all major web browsers have some form of built-in web
feed aggregator
most browsers can be extended via plug-ins, downloadable components that
provide additional features.
The following are some of the popular web browsers used now a
days to retrieve information on the internet.
a) HotJava
b) Netscape Navigator
c) Internet Explorer.
d) Mozilla FireFox.
1)Hot Java:- Sun Micro systems designed a browser called HotJava that
enables the display of interactive content on the web. Hot Java is written
completely in Java and demonstrates the capabilities of the Java
programming language. The browser makes web more dynamic and
interactive.
2) Netscape Navigator:-
Netscape communication Corporation developed a browser called Netscape
Navigator to interact with the web. It is a general purpose browser that can
run Java applets. It supports many platforms to work on. It supports scripting
languages like JavaScript, Vbscript etc.
3) Internet Explorer:-
Microsoft developed another popular browser called Internet Explorer. It uses
a Just-In-Time(JST) compiler which greatly increases the speed of execution.
4) Mozilla Firefox:-
Mozilla Firefox is the one of the best browsers out there on market. And it’s
free. Though the unique development methods of Open source, they are able
to make a product with impressive speed and fewer bugs than programs
developd by traditional methods. Mozilla Firefox has a number of unique
features, and it is overall a good product.
8
Prepared by [Link],[Link](CSE), Lecturer in computer science, SVDC,Titupati
Define XML document object model. Explain it’s Advantages
and disadvantages.
Document Object Model (DOM) it is used for accessing documents like HTML
and XML
The Document Object Model (DOM) is a programming API for HTML and XML
documents.
It defines the logical structure of documents and the way a document is
accessed and manipulated.
DOM defines the objects and properties and methods (interface) to access all
XML elements. It is separated into 3 different parts / levels −
1. Core DOM − standard model for any structured document
2. XML DOM − standard model for XML documents
3. HTML DOM − standard model for HTML documents
XML DOM is a standard object model for XML. XML documents have a hierarchy of
informational units called nodes; DOM is a standard programming interface of
describing those nodes and the relationships between them.
As XML DOM also provides an API that allows a developer to add, edit, move or
remove nodes at any point on the tree in order to create an application.
Following is the diagram for the DOM structure. The diagram depicts that parser
evaluates an XML document as a DOM structure by traversing through each node.
9
Prepared by [Link],[Link](CSE), Lecturer in computer science, SVDC,Titupati
Example
Consider the DOM representation of the following XML document [Link].
<?xml version = "1.0"?>
<Company>
<Employee category = "technical">
<FirstName>Tanmay</FirstName>
<LastName>Patil</LastName>
<ContactNo>1234567890</ContactNo>
</Employee>
<Employee category = "non-technical">
<FirstName>Taniya</FirstName>
<LastName>Mishra</LastName>
<ContactNo>1234667898</ContactNo>
</Employee>
</Company>
The Document Object Model of the above XML document would be as follows −
11
Prepared by [Link],[Link](CSE), Lecturer in computer science, SVDC,Titupati
4) Any Element:- You can declare an element using the ANY keyword in
the content. It is most often referred to as mixed category element.
Syntax
Following is the syntax for declaring elements with ANY content:
<!ELEMENT elementname ANY>
Here, the ANY keyword indicates that text (PCDATA) and/or any
elements declared within the DTD can be used within the content of
the <elementname> element.
5) Mixed element:- This is the combination of (#PCDATA) and children
elements. PCDATA stands for parsed character data, that is, text that is
not markup.
Syntax: <!ELEMENT elementname (#PCDATA|child1|child2)*>
The operator (*) must follow the mixed content declaration if children
elements are included
Attributes:
The attributes are used to specify the values of the element
These are specified with in double quotes
Ex: <flagtype=”true”>
The type of attribute of the element flag is having the value “true”.
CDATA:
Cdata stands for character data
This character data will be parsed by the parser
PCDATA:
It stands for Parsed Character data
Any parsable character data should not contain the markup characters
The markup characters are < > or &
If we want to use less than, greater than or ampersand characters than make use
of < > or &
Why DTD is used
Even XML file can be written in different formats by different people.
To avoid this issue and to standardize the XML data in to one format DTD is used.
Types of DTD:
1. Internal DTD
2. External DTD
Internal DTD:
1. If we are writing the DTD with in the XML document is called internal DTD
If the DTD is declared inline with in xml file
It should be declared in a “doctype” definition
The doctype definition is the first element in the document
It is also called as root elemnt
Syntax: <!DoCTYPE root-element[DTD rules>]
Example
DTD:-
12
Prepared by [Link],[Link](CSE), Lecturer in computer science, SVDC,Titupati
<!Doctype Student[
<!element Student (name,address, std, marks)>
<!element name (#pcdata)>
<!element address,(#pcdata)>
<!element Std(#pcdata)>
<!element markks(#pcdata)>
]>
For the above data we are writing XML data
Xml:-
<student>
<name> Anas</name>
<address>KNR</address>
<std>[Link]</std>
<marks>83 percent</marks>
</student>
Save this file [Link]
Internal DTD s are reusable.
External DTD:
If we are writing the DTD in a separate text based document and if we are
linking with XML that DTD is called external DTD.
In this type, an external dtd file is created and its name must be specified in
the corresponding xml file
If the DTD is declared in a external file, the <!DOCTYPE> definition must
contain a reference to an external DTD.
Following xml document describes the use of external dtd
Step1:Creation of dtd file[[Link]]
Open some suitable text editor or notepad
Type following code into it
14
Prepared by [Link],[Link](CSE), Lecturer in computer science, SVDC,Titupati
The web service unpacks the SOAP request and converts it into a command
that the application can understand.
The application processes the information as required and responds with a
new unique account number for that customer.
Next, the web service packages the response into another SOAP message,
which it sends back to the client program in response to its HTTP request.
The client program unpacks the SOAP message to obtain the results of the
account registration process.
******
Define WebServices and their Advantages.
A web service is a collection of open protocols and standards used for exchanging
data between applications or systems. Software applications written in various
programming languages and running on various platforms can use web services to
exchange data over computer networks like the Internet in a manner similar to
inter-process communication on a single computer. This interoperability(e.g
between Java and Pythan, or windows and Linux applications) is due to the use of
open standards.
Here are the benefits of using Web Services −
Exposing the Existing Function on the network
A web service is a unit of managed code that can be remotely invoked using
HTTP, that is, it can be activated using HTTP requests. Web services allows you to
expose the functionality of your existing code over the network. Once it is
exposed on the network, other application can use the functionality of your
program.
Interoperability
Web services allow various applications to talk to each other and share data and
services among themselves. Other applications can also use the web services. For
example, a VB or .NET application can talk to Java web services and vice versa.
Web services are used to make the application platform and technology
independent.
Standardized Protocol
Web services use standardized industry standard protocol for the communication.
All the four layers (Service Transport, XML Messaging, Service Description, and
Service Discovery layers) use well-defined protocols in the web services protocol
stack. This standardization of protocol stack gives the business many advantages
such as a wide range of choices, reduction in the cost due to competition, and
increase in the quality.
Low Cost Communication
Web services use SOAP over HTTP protocol, so you can use your existing low-cost
internet for implementing web services. This solution is much less costly
compared to proprietary solutions like EDI/B2B. Besides SOAP over HTTP, web
15
Prepared by [Link],[Link](CSE), Lecturer in computer science, SVDC,Titupati
services can also be implemented on other reliable transport mechanisms like
FTP.
SOAP
SOAP is an XML-based protocol for exchanging information between computers.
SOAP is a communication protocol.
SOAP is for communication between applications.
SOAP is a format for sending messages.
SOAP is designed to communicate via Internet.
SOAP is platform independent.
SOAP is language independent.
SOAP is simple and extensible.
SOAP allows you to get around firewalls.
SOAP will be developed as a W3C standard.
WSDL
WSDL is an XML-based language for describing web services and how to access
them.
WSDL stands for Web Services Description Language.
WSDL was developed jointly by Microsoft and IBM.
WSDL is an XML based protocol for information exchange in decentralized
and distributed environments.
WSDL is the standard format for describing a web service.
WSDL definition describes how to access a web service and what operations
it will perform.
WSDL is a language for describing how to interface with XML-based services.
WSDL is an integral part of UDDI, an XML-based worldwide business registry.
WSDL is the language that UDDI uses.
WSDL is pronounced as 'wiz-dull' and spelled out as 'W-S-D-L'.
UDDI
UDDI is an XML-based standard for describing, publishing, and finding web
services.
16
Prepared by [Link],[Link](CSE), Lecturer in computer science, SVDC,Titupati
UDDI stands for Universal Description, Discovery, and Integration.
UDDI is a specification for a distributed registry of web services.
UDDI is platform independent, open framework.
UDDI can communicate via SOAP, CORBA, and Java RMI Protocol.
UDDI uses WSDL to describe interfaces to web services.
UDDI is seen with SOAP and WSDL as one of the three foundation standards
of web services.
UDDI is an open industry initiative enabling businesses to discover each
other and define how they interact over the Internet.
When client sends request for a web page, the web server search for the
requested page if requested page is found then it will send it to client with
an HTTP response.
If the requested web page is not found, web server will the send an HTTP
response:Error 404 Not found.
If client has requested for some other resources then the web server will
contact to the application server and data store to construct the HTTP response.
There are also different ways to request content from a web server. The most
common request is the Hypertext Transfer Protocol(HTTP), but there are also other
requests like the internet Message Access Protocol(IMAP) or the File Transfer
Protocol(FTP).
The primary function of a web server is to deliver web pages to client. This
means delivary of HTML documents and any additional content that may be
included by a document, such as images, style sheets and Java scripts.
17
Prepared by [Link],[Link](CSE), Lecturer in computer science, SVDC,Titupati
A client, commonly a web browser or web crawler, initiates communication
by making a request for a specific resource using HTTP and the server responds
with the content of that resource, or an error message if unable to do so. The
resource is typically a real file on the servers secondary memory, but this is not
necessarily the case and depends on how the web server is implemented.
While the primary function is to serve content, a full of implementation of HTTP
also includes a way of receiving content forms. This feature is used for submitting
web forms, including uploading of files.
Many generic web servers also support server-side scripting e.g., Apache
HTTP server and PHP. This means that the behavior of the web server can be
scripted in separate files, while the actual server software remains unchanged.
Usually, this functionality is used to create HTML documents on-the-fly as opposed
to return documents. This is referred to as dynamic and static content respectively.
The former is primarily used for retrieving and/or modifying information in
databases. The latter is, however, typically much faster and easily catched.
Web servers are not only used for serving the world wide web, rather they
can also be found embedded in devices such as printers, routers, webcams and
serving only a local network. The web server may then be used as part of a system
for monitoring and/or administrating the device in question. This usually means
that no additional software has to be installed on the client computer, since only a
web browser is required.
Types of webservers:
Every Web server that is connected to the Internet is given a unique address made
up of a series of four numbers between 0 and 255 separated by periods. For
example, [Link] or [Link].
When you register a web address, also known as a domain name, such as
[Link] you have to specify the IP address of the Web server that will host the
site. You can load up with Dedicated Servers that can support your web-based
operations.
There are four leading web servers − Apache, IIS, lighttpd and Jagsaw. Apart from
these Web Servers, there are other Web Servers also available in the market but
they are very expensive. Major ones are Netscape's iPlanet, Bea's Web Logic and
IBM's WebSphere.
Apache HTTP Server
This is the most popular web server in the world developed by the Apache
Software Foundation. Apache web server is an open source software and can be
installed on almost all operating systems including Linux, Unix, Windows, FreeBSD,
Mac OS X and more. About 60% of the web server machines run the Apache Web
Server.
You can have Apache with tomcat module to have JSP and J2EE related support.
18
Prepared by [Link],[Link](CSE), Lecturer in computer science, SVDC,Titupati
You can have detailed information about this server at Apache HTTP Server
Internet Information Services
The Internet Information Server (IIS) is a high performance Web Server from
Microsoft. This web server runs on Windows NT/2000 and 2003 platforms ( and
may be on upcoming new Windows version also). IIS comes bundled with Windows
NT/2000 and 2003; Because IIS is tightly integrated with the operating system so it
is relatively easy to administer it.
You can have detailed information about this server at Miscrosoft IIS
lighttpd
The lighttpd, pronounced lighty is also a free web server that is distributed with
the FreeBSD operating system. This open source web server is fast, secure and
consumes much less CPU power. Lighttpd can also run on Windows, Mac OS X,
Linux and Solaris operating systems.
You can have detailed information about this server at lighttpd
Sun Java System Web Server
This web server from Sun Microsystems is suited for medium and large websites.
Though the server is free it is not open source. It however, runs on Windows, Linux
and Unix platforms. The Sun Java System web server supports various languages,
scripts and technologies required for Web 2.0 such as JSP, Java Servlets, PHP, Perl,
Python, Ruby on Rails, ASP and Coldfusion etc.
You can have detailed information about this server at Sun Java System Web
Server
Jigsaw Server
Jigsaw (W3C's Server) comes from the World Wide Web Consortium. It is open
source and free and can run on various platforms like Linux, Unix, Windows, Mac
OS X Free BSD etc. Jigsaw has been written in Java and can run CGI scripts and
PHP programs.
19
Prepared by [Link],[Link](CSE), Lecturer in computer science, SVDC,Titupati