• No results found

XML

N/A
N/A
Protected

Academic year: 2020

Share "XML"

Copied!
20
0
0

Loading.... (view fulltext now)

Full text

(1)

UNIT 5

XML

XML: defining data for web applications, basic XML, document type definition, presenting XML, document object model. Web Services

******************************************************************

DEFINING DATA FOR WEB APPLICATIONS:

A web application or "web app" is a software program that runs on a web server. Unlike traditional desktop applications, which are launched by your operating system, web apps must be accessed through a web browser.

Web apps have several advantages over desktop applications. Since they run inside web browsers, developers do not need to develop web apps for multiple platforms.

For example, a single application that runs in Chrome will work on both Windows and OS X. Developers do not need to distribute software updates to users when the web app is updated. By updating the application on the server, all users have access to the updated version.

From a user standpoint, a web app may provide a more consistent user interface across multiple platforms because the appearance is dependent on the browser rather than the operating system.

Additionally, the data you enter into a web app is processed and saved remotely. This allows you to access the same data from multiple devices, rather than transferring files between computer systems.

While web applications offer several benefits, they do have some disadvantages compared to desktop applications. Since they do not run directly from the operating system, they have limited access to system resources, such as the CPU, memory, and the file system.

(2)

on the web browser. If your browser crashes, for example, you may lose your unsaved progress. Also, browser updates may cause incompatibilities with web apps, creating unexpected issues.

Some people prefer desktop apps, while others prefer web applications. Therefore, many software companies now offer both desktop and web versions of their most popular programs. Common examples include Microsoft Office, Apple iWork, and Intuit TurboTax.

In most cases, files saved in the online version are compatible with the desktop version and vice versa.

For example, if you save a .TAX2013 file in TurboTax Online, you can open and edit the file with the desktop version.

******************************************************************

What is XML

XML stands for Extensible Markup Language. It is a text-based markup language derived from Standard Generalized Markup Language (SGML).

XML tags identify the data and are used to store and organize the data, rather than specifying how to display it like HTML tags, which are used to display the data. XML is not going to replace HTML in the near future, but it introduces new possibilities by adopting many successful features of HTML.

There are three important characteristics of XML that make it useful in a variety of systems and solutions −

XML is extensible − XML allows you to create your own self-descriptive tags, or language, that suits your application.

XML carries the data, does not present it − XML allows you to store the data irrespective of how it will be presented.

XML is a public standard − XML was developed by an organization called the World Wide Web Consortium (W3C) and is available as an open standard.

(3)

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.

4) XML simplifies Platform change

(4)

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.

************************************************************************

HTML vs XML

There are many differences between HTML (Hyper Text Markup Language) and XML (eXtensible Markup Language). The important differences are given below:

HTML XML

HTML is used to display data and focuses on how data looks.

XML is a software and hardware independent tool used to transport and store data. It focuses on what data is.

HTML is a markup language itself. XML provides a framework to define markup languages.

HTML is not case sensitive. XML is case sensitive.

HTML is a presentation language. XML is neither a presentation language nor a programming language.

HTML has its own predefined tags. You can define tags according to your need.

In HTML, it is not necessary to use a closing tag.

XML makes it mandatory to use a closing tag.

HTML is static because it is used to display data.

XML is dynamic because it is used to transport data.

HTML does not preserve whitespaces. XML preserve whitespaces.

(5)

Applications of XML:

 Electronic commerce

 Financial fund transfer

 Exchanging multimedia messages

 Built-in environment for data transfer

************************************************************************

Basic XML:

XML documents use a simple syntax Ex: <?xml version="1.0"?>

<author> <name>

<fname>Ravi</fname> <lname>Kumar</lname> </name>

</author> o/p:

 The first line is the XML declaration. It defines version of the XML document.

 The next line describes the root element of the document (author)

 The next line describes the sub element (name)

(6)

Pictorial representation for the above program:

************************************************************************

Valid XML and Well Formed XML:

XML documents may be either valid or well formed.

Well-formed XML

If a document is syntactically correct then it can be called as well formed XML. That means it is the one which follows the rules of XML.

Basic rules of well-formed XML are:

 Every open tag must be closed

 Every open tag has exactly one closed tag

 All elements must be embed with in one root tag

 Child tag must be closed before the parent tag

Valid XML

A valid XML document has its own DTD.

A well-formed and valid XML document is one which has been validated against DTD.

(7)

 These rules can be written by the author of the XML document

 The rules determine the type of data that each part of the document can contain

Basic building blocks of XML document

The XML document contains following building blocks

1. Tags

2. Elements

3. Attributes

4. CDATA

5. PCDATA

6. Entities

Simple example on XML:

Tags:

Tags are essential in any scripting language. Using these tags we can embed any elements in XML document.

Ex: <fname>Ravi</fname>

Elements:

There are major entities to represent the data in XML. These entities are also called as elemets.

Ex: name, fname, lname

(8)

Element may belong to CDATA or PCDATA.

CDATA:

CDATA means character data and PCDATA means parsed character data.With CDATA parsing will not be performed to the data whereas with PCDATA parsing will be done.

Parsing:

Validating the XML document according to the syntax of the XML document. There are 2 types of Parsers.

1. DOM parser(Document Object Model)

2. SAX Parser(Simple API for XML)

<!ELEMENT name-of-the-element (#PCDATA)>

<!ELEMENT name-of-the-element (#CDATA)>

If elements contain child elements then the syntax is:

<!ELEMENT name-of-the-element(child elements names)>

Attributes:

Giving additional information to an element is nothing but an attribute. Attribute is defined only after element declaration only.

Attribute is defined by using the keyword ‘ATTLIST’ (capital letters)

Syntax: <! ATTLIST name-of- the-element name- of- the- attribute type-of-the-attribute default-value>

Attributes contains below values:

CDATA:

(9)

PCDATA:

Here the attribute value is parsed character data. This data is parsed by parsers. These attribute values are treated as special tags and compares these elements with XML syntax.

Default value: It specifies the initial values of an attribute.

There are 3 types of default values for an attribute.

#REQUIRED: It specifies particular attribute is essential.

#IMPLIED: It specifies particular attribute is not .

#FIXED: It specifies the attribute contains fixed value.

Ex:

DTD: <!ATTLIST ramu address CDATA #REQUIRED>

XML: <ramu address=”BVRM”>

Entities:

An entity is a symbolic representation of information. Some markup elements contain complex data. These elements are called as entities.

There are 2 types of entities.

 Internal entities

 External entities

Internal entities: Generally reference text.

Syntax: <!ENTITY name “entity-value”>

Ex: <?xml version=”1.0”>

<!DOCTYPE letter[

(10)

]>

<letter>&hbd;</letter>

When the entity is included, then the name in the XML is preceded with ampersand and followed by a semi colon(&hbd;)

External entities:

External entities are useful for creating a common reference that can be shared with multiple documents. Any changes that made to external entities are automatically updated in the documents they are referenced.

There are 2 types of external entities: private and public

Private external entities are identified by the keyword ‘SYSTEM’. This is basically used for single author or group of authors.

<!ENTITY name SYSTEM “URI”>

Public external entities are identified by the keyword ‘PUBLIC’. This is basically used for broad use.

<!ENTITY name PUBLIC “public_ID” “URI”>

************************************************************************

Document Type Definition (DTD):

DTD defines the document structure with a list of legal elements and attributes. A DTD can be declared as internally or externally. “It contains legal building blocks for an XML document.”

Internal DTD:

 In internal DTD, Document type declaration must be placed between the XML declaration and the root element in the document.

 The keyword DOCTYPE, must be followed by the root element in the XML document.

(11)

Example for Internal DTD:

<?xml version="1.0"?>

<!DOCTYPE author[

<!ELEMENT author (name)*>

<!ELEMENT name (fname,lname)>

<!ELEMENTfname (#PCDATA)>

<!ELEMENTlname (#PCDATA)>

]>

<author>

<name>

<fname>Ravi</fname>

<lname>Varma</lname>

</name>

</author>

Save this file as test.XML and open this file in the browser.

Output:

(12)

 <!ELEMENT name (fname,lname)> defines element name contains 2 Childs(fname and lname)

 <!ELEMENTfname (#PCDATA)> defines fname to be of type PCDATA.

 <!ELEMENTlname (#PCDATA)> defines lname to be of type PCDATA.

External DTD:

In external DTD, DTD is written in an external file and that can be included in an XML file.

<?xml version="1.0"?>

<!DOCTYPE author SYSTEM "author.dtd">

<author>

<name>

<fname>Ravi</fname>

<lname>Varma</lname>

</name>

</author>

Save this file as test.XML.

we need to create “author.dtd” as follows:

<!ELEMENT author (name)*>

<!ELEMENT name (fname,lname)>

<!ELEMENTfname (#PCDATA)>

<!ELEMENTlname (#PCDATA)>

(13)

Output

:

************************************************************************

There are 2 types of Parsers available in XML:

1. DOM(Document Object model)

2. SAX(Simple API for XML)

Document Object Model (DOM):

The DOM represents XML document as a tree. Tree contains a global view of the document. This makes navigation of the document easy, modify any sub-tree.

The XML DOM is:

 A standard object model for XML

 A standard programming interface for XML  Platform and Language independent

 A W3C standard

The XML Dom defines the objects and properties of all XML elements and their methods to access them.

In other words XML DOM is a standard for how to get, change, add, delete XML elements.

Example:

<?xml version="1.0"?> <books>

<book>

<author>Rani</author>

<price format="dollar">31.95</price> <pubdate>12/12/2015</pubdate> </book>

<pubinfo>

(14)

</books>

Output:

The following diagram shows the DOM structure for the above program:

With the XML DOM we can access and modify specific nodes. we can retrieve each node element easily with DOM.

Example 2:

<TABLE>

<ROWS> <TR>

<TD>A</TD> <TD>B</TD>

(15)

</TR> <TR>

<TD>C</TD> <TD>D</TD> </TR>

</ROWS> </TABLE>

************************************************************************

What is web Server?

Web server is software or a program based on client-server model. It is commonly used for website hosting.

When the client sends a request for a file through HTTP protocol, it sends back the response in form of HTML text. The files are stored on the Internet in form of webpage.

Every computer connected to Internet is supposed to have a web server to open a website. Apache and Microsoft’s IIS(Internet Information Server) are most commonly used web servers.

(16)

1. Internet- As the name suggests, it is collection of several computers which are inter-connected to each other. The network between the computers slows them to communicate with each other.

2. Clients and servers

The whole network system works on two types of system- client and server. The computer machine which provides services to the other machines is known as servers. And the machines which request for the services are known as clients.

3. IP address: It is a unique address assigned to each machine available on the Internet. 4. Domain names:

It is difficult for humans to remember the IP address. Therefore, they are provided a name known as domain. Domain names are human readable names assigned to each IP address.

5. Name servers:

It is a set of servers which is used to map the domain names to the IP addresses. It is a form of database which maps the human readable names to IP address and is distributed all over the Internet.

Example: nsX.hostgator.com

6. Port:

Each server machine is assigned a port number to provide its services to other machines. Some of the commonly used port numbers are: 80 for WWW, 21 for FTP server, 23 for telnet

7. Protocol- It is a set of rules used for communication over Internet.

8. URL:

Abbreviated form of Uniform Resource Locator is the unique address of the files available on Internet. It is constituted in three parts.

a. The protocol( e.g. HTTP or FTP)

b. The domain name( e.g. www.bvrice.com)

c. The file name(e.g. 13763-Resource-posting-guidelines.aspx)

(17)

When the URL of a website is entered in the browser, the browser connects to the server and sends a request for the page. After the complete processing, the servers send back the requested page. And finally the user is able to view the page on the computer screen. So, the three processes are involved in the complete scenario.

1. Establishing a connection 2. Sending a request

3. Responding to the request

Detailed description of the complete processing of the requested web page

As soon as the user enters the URL, it is divided into three parts: protocol, domain name and file name.

Here is step-by-step procedure

1. The domain name is mapped with the IP address through domain name servers. This is done to connect it with the server machine.

2. The browser then establishes a connection with the server machine at the provided IP address on the port available for the particular server machine.

3. After the connection is established, browser sends a request to the server and asks to provide the particular file.

If it in case, the pages do not exist or some other error occurs, it will send the appropriate error message.

(18)

Error 404, while trying to open a webpage, which is the message sent by the server when the page does not exist. Error 401 when access is denied to us due to incorrect credentials, like username or password, provided by us.

4. The server then sends the HTML text of the requested file or web page to the browser. 5. The browser then read the HTML tags in the text file and formats the page onto the screen

Architecture

Web Server Architecture follows the following two approaches:

1. Concurrent Approach

2. Single-Process-Event-Driven Approach.

1. Concurrent Approach

Concurrent approach allows the web server to handle multiple client requests at the same time. It can be achieved by following methods:

 Multi-process

 Multi-threaded

 Hybrid method.

Multi-processing

In this a single process (parent process) initiates several single-threaded child processes and distribute incoming requests to these child processes. Each of the child processes are responsible for handling single request.

It is the responsibility of parent process to monitor the load and decide if processes should be killed or forked.

Multi-threaded

Unlike Multi-process, it creates multiple single-threaded process.

(19)

It is combination of above two approaches. In this approach multiple process are created and each process initiates multiple threads. Each of the threads handles one connection. Using multiple threads in single process results in less load on system resources.

Example of working of the web server

Suppose, the user enters a URL http://www.webopedia.com/Web_server.html

1. As soon as the user enters the URL, it is divided in three parts.

 First, the protocol i.e. HTTP

 Second, the domain name, www.webopedia.com

 And third and the final, file name, Web_server.html

2. The domain name servers maps the domain name www.webopedia.com to the IP address.

3. WWW is available on port number 80. So, the browser forms a connection on the port 80 at that IP address.

4. Since, the protocol being used is HTTP; browser sends a GET request to the web server.

5. The web server sends a response in form of HTML text file which is formatted and displayed on the screen.

Finally, the user is able to view the requested webpage on the screen.

S.N. Web Server Description

1

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.

2. Internet Information Services (IIS)

(20)

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.

3.

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.

4.

Sun Java System Web Server

This web server from Sun Microsystems is suited for medium and large web sites. 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, and Ruby on Rails, ASP and

Coldfusion etc.

5.

Jigsaw Server

References

Related documents

Commercial aircraft programs inventory included the following amounts related to the 747 program: $448 of deferred production costs at December 31, 2011, net of previously

○ If BP elevated, think primary aldosteronism, Cushing’s, renal artery stenosis, ○ If BP normal, think hypomagnesemia, severe hypoK, Bartter’s, NaHCO3,

I problematize three family images associated with the design and implementation of housing projects: the bureaucratic family, envisaged by policymakers as conflating with a model

The encryption operation for PBES2 consists of the following steps, which encrypt a message M under a password P to produce a ciphertext C, applying a

Results suggest that the probability of under-educated employment is higher among low skilled recent migrants and that the over-education risk is higher among high skilled

In summary and taking into account the resonance characteristics of the ACUREX plant, the main contribution of this paper, is to improve a gain schedul- ing (GS) predictive

more than four additional runs were required, they were needed for the 2 7-3 design, which is intuitive as this design has one more factor than the 2 6-2 design

4.1 The Select Committee is asked to consider the proposed development of the Customer Service Function, the recommended service delivery option and the investment required8. It