Web Technology - Unit Wise Questions

Questions Organized by Units
Unit 1: Introduction
37 Questions

1.  Explain the web server concept. Why internet is a client/server technology?

10 marks
Details
Official Answer

Web server is a program or a computer that can provide services to other programs called clients. A web server can contain one or more websites. A web server processes the incoming requests.

  • The primary function of web server is to store, process and deliver web pages to clients. The communication between client and server takes place using the HTTP. Pages delivered are most frequently HTML documents, which ,may include images, style sheets.
  • A web browser initiates the communication by making a request for a specific resources using HTTP and the server responds with the content of that resources or an error message if unable to do so.

Web server features:

  • Always wait for a request from a client;
  • Serves clients’ requests, then responds with the requested data to clients;
  • A server can communicate with other servers in order to meet a client’s request.

Client-server is a computer model that separates client and server, and usually interlinked using a computer network. Each instance of a client can send data requests to one of the servers online and expect a response. In turn, some of the available servers can accept these requests, process them and return the result to the client. Often clients and servers communicate through a computer network with separate hardware, but the client and server can reside on the same system. The machine is a host server that is running one or more server programs that share their resources with clients. A client does not share its resources, but requests content from a server or service function. Clients, therefore, initiate communication sessions with the servers that wait for incoming requests.

Internet is a client/server technology because most services that are accessed via the Internet work on the client/server model. In that, we have a server which provides a service, while clients connect to the server to make requests regarding the service. A web site is an example: a web server holds the contents of the web site. Our web browser is a client, which we can use to connect to web servers to ask them for information, or to perform services on our behalf.

AI Generated Answer

AI is thinking...

1.  How does a web server link physically on the Internet? How do we navigate from one URL to another from a page displayed at a browser? Explain.

10 marks
Details
Official Answer

The web server works as follows:

  • A user enters a URL into a browser (for example, google.com). This request is passed to a domain name server.
  • The domain name server returns an IP address for the server that hosts the Website (for example, 68.178.157.132).
  • The browser requests the page from the Web server using the IP address specified by the domain name server.
  • The Web server returns the page to the IP address specified by the browser requesting the page. The page may also contain links to other files on the same server, such as images, which the browser will also request.
  • The browser collects all the information and displays to your computer in the form of Web page.


Navigation in web page is simple. It use a single link tag termed as Anchor Tag <a>. By using anchor tag we can navigate from different portion of site, another web site. Generally navigation has three techniques

• Internal navigation (Navigation inside site)

• External Navigation (Navigate to third party site)

• Intra Navigation (Navigate with in web page for easy scrolling)

The following example demonstrate navigation technique in web browser.

<html>

 <head>

 <title>Navigation example</title>

 </head>

 <body>

    <h2 id="C4">Chapter 4</h2>

    <a href="#C4">Jump to Chapter 4</a>

    <a href="/images/flower.jpg">Open flower Picture of site (internal Link)</a>

    <a href="http://www.facebook.com/collegenote">Open facebook site (External Link)</a>

 </body>

 </html> 

AI Generated Answer

AI is thinking...

1.  Explain the architectural issues of web layer with example.

10 marks
Details
Official Answer

The web layer is also referred to as the UI layer. The web layer is primarily concerned with presenting the user interface and the behavior of the application (handling user interactions/events). While the web layer can also contain logic, core application logic is usually located in the services layer. The three Layers within the Web Layer are:

HTML-The Content Layer: The content layer is where you store all the content that your customers want to read or look at. This includes text and images as well as multimedia. It's also important to make sure that every aspect of your site is represented in the content layer. That way, your customers who have JavaScript turned off or can't view CSS will still have access to the entire site, if not all the functionality.

CSS - the Styles Layer: Store all your styles for your Web site in an external style sheet. This defines the way the pages should look, and you can have separate style sheets for various media types. Store your CSS in an external style sheet so that you can get the benefits of the style layer across the site.

JavaScript - the Behavior Layer: JavaScript is the most commonly used language for writing the behavior layer; ASP, CGI and PHP can also generate Web page behaviors. However, when most developers refer to the behavior layer, they mean that layer that is activated directly in the Web browser - so JavaScript is nearly always the language of choice. You use this layer to interact directly with the DOM or Document Object Model.

Benefits of separating the layers are:

  • Shared resources
  • Faster downloads
  • Multi-person teams
  • Accessibility
  • Backwards compatibility
AI Generated Answer

AI is thinking...

1.  Explain the 2-Tier, 3-Tier and n-Tier technology with its architecture.

10 marks
Details
Official Answer

2-Tier Architecture

2-tier architecture is used to describe client/server systems where the client requests resources and the server responds directly to the request, using its own resources. This means that the server does not call on another application in order to provide part of the service. It runs the client processes separately from the server processes, usually on a different computer.

Networking: 3-Tier Client/Server Architecture - CCM

3-Tier Architecture

In 3-tier architecture, there is an intermediary level, meaning the architecture is generally split up between:

 A client, i.e. the computer, which requests the resources, equipped with a user interface (usually a web browser) for presentation purposes

– The application server (also called middleware), whose task it is to provide the requested resources, but by calling on another server

– The data server, which provides the application server with the data it requires.

Networking: 3-Tier Client/Server Architecture - CCM

N-Tier Architecture (multi-tier)

N-tier architecture (with N more than 3) is really 3 tier architectures in which the middle tier is split up into new tiers. The application tier is broken down into separate parts. These parts are differs from system to system. The primary advantage of N-tier architectures is that they make load balancing possible. Since the application logic is distributed between several servers, processing can then be more evenly distributed among those servers. N-tiered architectures are also more easily scalable, since only servers experiencing high demand, such as the application server, need be upgraded. The primary disadvantage of N-tier architectures is that it is also more difficult to program and test an N-tier architecture due to its increased complexity. 

 

AI Generated Answer

AI is thinking...

1. Differentiate between 2-Tier, 3-Tier and n-Tier.

10 marks
Details
Official Answer

2-Tier Architecture

2-tier architecture is used to describe client/server systems where the client requests resources and the server responds directly to the request, using its own resources. This means that the server does not call on another application in order to provide part of the service. It runs the client processes separately from the server processes, usually on a different computer.

Networking: 3-Tier Client/Server Architecture - CCM

3-Tier Architecture

In 3-tier architecture, there is an intermediary level, meaning the architecture is generally split up between:

 A client, i.e. the computer, which requests the resources, equipped with a user interface (usually a web browser) for presentation purposes

– The application server (also called middleware), whose task it is to provide the requested resources, but by calling on another server

– The data server, which provides the application server with the data it requires.

Networking: 3-Tier Client/Server Architecture - CCM

N-Tier Architecture (multi-tier)

N-tier architecture (with N more than 3) is really 3 tier architectures in which the middle tier is split up into new tiers. The application tier is broken down into separate parts. These parts are differs from system to system. The primary advantage of N-tier architectures is that they make load balancing possible. Since the application logic is distributed between several servers, processing can then be more evenly distributed among those servers. N-tiered architectures are also more easily scalable, since only servers experiencing high demand, such as the application server, need be upgraded. The primary disadvantage of N-tier architectures is that it is also more difficult to program and test an N-tier architecture due to its increased complexity. 

 

AI Generated Answer

AI is thinking...

1.  Define HTTP. Explain the overall function of HTTP with example.

10 marks
Details
Official Answer

HTTP is a TCP/IP based communication protocol, that is used to deliver data (HTML files, image files, query results, etc.) on the World Wide Web. The default port is TCP 80, but other ports can be used as well. It provides a standardized way for computers to communicate with each other. HTTP specification specifies how clients' request data will be constructed and sent to the server, and how the servers respond to these requests.

There are three important features of HTTP:

  • HTTP is connectionless: After a request is made, the client disconnects from the server and waits for a response. The server must re-establish the connection after it processes the request.
  • HTTP is media independent: Any type of data can be sent by HTTP as long as both the client and server know how to handle the data content. How content is handled is determined by the MIME specification.
  • HTTP is stateless: This is a direct result of HTTP's being connectionless. The server and client are aware of each other only during a request. Afterwards, each forgets the other. For this reason neither the client nor the browser can retain information between different requests across the web pages.

The following diagram shows a very basic architecture of a web application and depicts where HTTP sits:

HTTP Architecture

The HTTP protocol is a request/response protocol based on the client/server based architecture where web browsers, robots and search engines, etc. act like HTTP clients, and the Web server acts as a server.

Client:

The HTTP client sends a request to the server in the form of a request method, URI, and protocol version, followed by a MIME-like message containing request modifiers, client information, and possible body content over a TCP/IP connection.

Server:

The HTTP server responds with a status line, including the message's protocol version and a success or error code, followed by a MIME-like message containing server information, entity meta information, and possible entity-body content.

AI Generated Answer

AI is thinking...

2.  Differentiate between HTTP and FTP. Discuss 3-tier technology with suitable example.

10 marks
Details
Official Answer

Difference between HTTP and FTP

HTTP: HTTP is a Hyper Text Transfer Protocol. It helps in accessing data from the World Wide Web.

FTP: FTP is a File Transfer Protocol. It is used to copy a file from one host to another.

  • The basic difference between HTTP and FTP is that HTTP is used to access different websites on the internet. On the other hand, the FTP is used to transfer files from one host to the another.
  • HTTP establishes data connection only whereas, the FTP establishes data as well as control connection.
  • HTTP uses the TCP’s port number 80 whereas, FTP uses TCP’s port number 20 and 21.
  • In case you are using HTTP, http appears in the URL of the website and if you are using FTP, ftp appears in your URL.
  • HTTP is efficient to transfer smaller files like web pages whereas, FTP is efficient to transfer large files.
  • HTTP does not require authentication whereas, FTP uses the password for authentication.
  • Web pages or data content transferred to a device using HTTP are not saved in the memory of that device whereas, the data delivered to a device using FTP is saved in the memory of that device.

 3-Tier Architecture

In 3-tier architecture, there is an intermediary level between client and server, meaning the architecture is generally split up between:

 A client, i.e. the computer, which requests the resources, equipped with a user interface (usually a web browser) for presentation purposes

– The application server (also called middleware), whose task it is to provide the requested resources, but by calling on another server

– The data server, which provides the application server with the data it requires.

Networking: 3-Tier Client/Server Architecture - CCM

AI Generated Answer

AI is thinking...

2.  List the protocols and their use at the application layer in the Internet. Why World Wide Web is use? Explain.

10 marks
Details
Official Answer

An application layer protocol defines how application processes (clients and servers), running on different end systems, pass messages to each other. Some protocols used in application layer are discussed below:

1. HTTP (Hypertext Transfer Protocol):

    This is a protocol used mainly to access data on the world wide web(WWW). It is a protocol which governs the communication between the client and server.

2. TELNET (Terminal Network):

    TELNET is a client-server application that allows a user to log onto remote machine and lets the user to access any application program on a remote computer.

3. FTP (File Transfer Protocol):

    FTP is the standard mechanism provided by TCP/IP for transferring a file from one host to another. Transferring file from a client computer to a server computer is called uploading and transferring from server to a client is downloading. 

4. SMTP (Simple Mail Transfer Protocol)

    The TCP/IP protocol that supports electronic mail on the internet is called SMTP. It transfers messages from senders' mail servers to the recipents' mail servers using TCP connections. SMTP provides services for mail exchange between users on the same or different computers.

5. POP (Post Office Protocol):

    This is a protocol used by a mail server in conjunction with SMTP to receive and holds mail for hosts. POP3 mail server receives e-mails and filters them into the appropriate user folders. When a user connects to the mail server to retrieve his mail, the messages are downloaded from mail server to the user's hard disk.


The World Wide Web (WWW) is a system that we use to access the Internet. The WWW is hypertext based information retrieval tool, it uses the hypertext to access the various forms of information available on the world’s different networks. One can easily surf the Web by jumping from one document to another using the links in those documents. These documents can be in many formats, such as text, graphics, animation, sound and latest is video. They may also be a combination of all these. All the information on Internet are presented to the user as a document or more popularly known as Web Page. All these Web Pages are link to each other or even to section within a Web Page. And these links are known as Hyper Links.

AI Generated Answer

AI is thinking...

2.  Explain the client tier with example.

10 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

2.  What is FTP? Discuss its functions in detail.

10 marks
Details
Official Answer

File transfer protocol (FTP) is a set of rules that computers follow for the transferring of files from one system to another over the internet. It is mainly used for transferring the web page files from their creator to the computer that acts as a server for other computers on the internet. It is also used for downloading the files to computer from other servers.

When a user wishes to engage in File transfer, FTP sets up a TCP connection to the target system for the exchange of control messages. These allow used ID and password to be transmitted and allow the user to specify the file and file action desired. Once file transfer is approved, a second TCP connection is set up for data transfer. The file is transferred over the data connection, without the overhead of headers, or control information at the application level. When the transfer is complete, the control connection is used to signal the completion and to accept new file transfer commands.


Fig: Basic model of FTP

FTP can be run in active or passive mode, which determines how the data connection is established. In active mode, the server initiates the data connection with the client after the client has established a connection on the command channel. In passive mode it is the other way round, the client initiates the data connection with the server.

FTP includes three different transmission modes: stream, block and compressed. In stream mode, data is sent as a continuous sequence of bytes to TCP; in block mode, data is formatted into blocks with headers and then passes it on to TCP; and in compressed mode, bytes are compacted using run-length encoding. Stream mode is the one most commonly used.

AI Generated Answer

AI is thinking...

3.  What is HTTP? Discuss its function in detail.

10 marks
Details
Official Answer

HTTP is a TCP/IP based communication protocol, that is used to deliver data (HTML files, image files, query results, etc.) on the World Wide Web. The default port is TCP 80, but other ports can be used as well. It provides a standardized way for computers to communicate with each other. HTTP specification specifies how clients' request data will be constructed and sent to the server, and how the servers respond to these requests.

There are three important features of HTTP:

  • HTTP is connectionless: After a request is made, the client disconnects from the server and waits for a response. The server must re-establish the connection after it processes the request.
  • HTTP is media independent: Any type of data can be sent by HTTP as long as both the client and server know how to handle the data content. How content is handled is determined by the MIME specification.
  • HTTP is stateless: This is a direct result of HTTP's being connectionless. The server and client are aware of each other only during a request. Afterwards, each forgets the other. For this reason neither the client nor the browser can retain information between different requests across the web pages.

The following diagram shows a very basic architecture of a web application and depicts where HTTP sits:

HTTP Architecture

The HTTP protocol is a request/response protocol based on the client/server based architecture where web browsers, robots and search engines, etc. act like HTTP clients, and the Web server acts as a server.

Client:

The HTTP client sends a request to the server in the form of a request method, URI, and protocol version, followed by a MIME-like message containing request modifiers, client information, and possible body content over a TCP/IP connection.

Server:

The HTTP server responds with a status line, including the message's protocol version and a success or error code, followed by a MIME-like message containing server information, entity meta information, and possible entity-body content.

AI Generated Answer

AI is thinking...

4.  List the common application of web server.

5 marks
Details
Official Answer

Web server is a program or a computer that can provide services to other programs called clients. A web server can contain one or more websites. A web server processes the incoming requests.

  • The primary function of web server is to store, process and deliver web pages to clients. The communication between client and server takes place using the HTTP. Pages delivered are most frequently HTML documents, which ,may include images, style sheets.
  • A web browser initiates the communication by making a request for a specific resources using HTTP and the server responds with the content of that resources or an error message if unable to do so.

Here is the list of common application of web server

  • A web server‘s fundamental job is to accept and fulfill requests from clients for static content from a website (HTML pages, files, images, video, and so on).
  • The client is almost always a browser or mobile application and the request takes the form of a Hypertext Transfer Protocol (HTTP) message, as does the web server’s response.
  • web server in Java is used to host Java web application.
  • Web Server supports Servlets and JSP.
AI Generated Answer

AI is thinking...

4.  Discuss internet as a client/server technology.

5 marks
Details
Official Answer

Client-server is a computer model that separates client and server, and usually interlinked using a computer network. Each instance of a client can send data requests to one of the servers online and expect a response. In turn, some of the available servers can accept these requests, process them and return the result to the client. Often clients and servers communicate through a computer network with separate hardware, but the client and server can reside on the same system. The machine is a host server that is running one or more server programs that share their resources with clients. A client does not share its resources, but requests content from a server or service function. Clients, therefore, initiate communication sessions with the servers that wait for incoming requests.

Internet is a client/server technology because most services that are accessed via the Internet work on the client/server model. In that, we have a server which provides a service, while clients connect to the server to make requests regarding the service. A web site is an example: a web server holds the contents of the web site. Our web browser is a client, which we can use to connect to web servers to ask them for information, or to perform services on our behalf.

AI Generated Answer

AI is thinking...

4.  What is client/server technology? Differentiate between web client and web server.

5 marks
Details
Official Answer

Client-server is a computer model that separates client and server, and usually interlinked using a computer network. Each instance of a client can send data requests to one of the servers online and expect a response. In turn, some of the available servers can accept these requests, process them and return the result to the client. Often clients and servers communicate through a computer network with separate hardware, but the client and server can reside on the same system. The machine is a host server that is running one or more server programs that share their resources with clients. A client does not share its resources, but requests content from a server or service function. Clients, therefore, initiate communication sessions with the servers that wait for incoming requests.


Difference between web client and web server

Web Client /web browsersWeb Server

It is an application program that acts as an interface between server and client and displays web document to the client.

It is a program or the computer that provide services to other programs called client.
Web client requests the server for the web pages and services.Web server stores, process and deliver the web pages to web browsers.
It sends HTTP requests and get HTTP response.It gets HTTP requests and sends HTTP responses.
The web browsers is installed on the client computer.The web servers can be a remote machine placed at the other side of the network.
Web browser stores the cookies for different websites.Web servers provide an area to store and organize the pages of websites.
It is a simple and less powerful machine.It is powerful and expensive machine.
It supports single user login at a time.It supports multi-user login at a time.
AI Generated Answer

AI is thinking...

4. Describe client server architecture with its types.

5 marks
Details
Official Answer

Client server architecture consists of two kinds of computers: clients and servers. Clients are the computers that that do not share any of its resources but requests data and other services from the server computers and server computers provide services to the client computers by responding to client computers requests.

Client/Sever architecture can be of different model based on the number of layers it holds. Some of them are;

1. 2-Tier Architecture

2-tier architecture is used to describe client/server systems where the client requests resources and the server responds directly to the request, using its own resources. This means that the server does not call on another application in order to provide part of the service. It runs the client processes separately from the server processes, usually on a different computer.

Networking: 3-Tier Client/Server Architecture - CCM

2. 3-Tier Architecture

In 3-tier architecture, there is an intermediary level, meaning the architecture is generally split up between:

A client, i.e. the computer, which requests the resources, equipped with a user interface (usually a web browser) for presentation purposes

– The application server (also called middleware), whose task it is to provide the requested resources, but by calling on another server

– The data server, which provides the application server with the data it requires.

Networking: 3-Tier Client/Server Architecture - CCM

3. N-Tier Architecture (multi-tier)

N-tier architecture (with N more than 3) is really 3 tier architectures in which the middle tier is split up into new tiers. The application tier is broken down into separate parts. These parts are differs from system to system.

 

AI Generated Answer

AI is thinking...

4.  What is client/server technology? Discuss Internet as a client/server technology.

5 marks
Details
Official Answer

Client-server is a computer model that separates client and server, and usually interlinked using a computer network. Each instance of a client can send data requests to one of the servers online and expect a response. In turn, some of the available servers can accept these requests, process them and return the result to the client. Often clients and servers communicate through a computer network with separate hardware, but the client and server can reside on the same system. The machine is a host server that is running one or more server programs that share their resources with clients. A client does not share its resources, but requests content from a server or service function. Clients, therefore, initiate communication sessions with the servers that wait for incoming requests.

Internet is a client/server technology because most services that are accessed via the Internet work on the client/server model. In that, we have a server which provides a service, while clients connect to the server to make requests regarding the service. A web site is an example: a web server holds the contents of the web site. Our web browser is a client, which we can use to connect to web servers to ask them for information, or to perform services on our behalf.

AI Generated Answer

AI is thinking...

4.  Explain the uses of a web server.

5 marks
Details
Official Answer

Web server is a program or a computer that can provide services to other programs called clients. A web server can contain one or more websites. A web server processes the incoming requests.

  • The primary function of web server is to store, process and deliver web pages to clients. The communication between client and server takes place using the HTTP. Pages delivered are most frequently HTML documents, which ,may include images, style sheets.
  • A web browser initiates the communication by making a request for a specific resources using HTTP and the server responds with the content of that resources or an error message if unable to do so.

Web server features:

  • Always wait for a request from a client;
  • Serves clients’ requests, then responds with the requested data to clients;
  • A server can communicate with other servers in order to meet a client’s request.

Basic functionality:

  • It receives HTTP request via TCP
  • It maps Host header to specific virtual host (one of many host names sharing an IP address)
  • It maps Request-URI to specific resource associated with the virtual host

                - File: Return file in HTTP response

                - Program: Run program and return output in HTTP response

  • It maps type of resource to appropriate MIME type and use to set Content-Type header in HTTP response
  • It Logs information about the request and response
  • All e-commerce site require basic Web server software to answer requests from customers like ; Apache ,Microsoft’s Internet Information Server (IIS)
AI Generated Answer

AI is thinking...

5.  Explain the functions of web caches.

5 marks
Details
Official Answer

A web cache is a HTTP cache for temporary storage of web documents such as HTML pages & images. It helps in temporary storage of frequently accessed static content.

Internet users with similar interests often download the same web content over and over again. Without a proper web cache, every time a user makes request the response must come from the origin server. When many users are requesting content at the same time, response time may increase and server overload may even occur.

Whenever content is downloaded from the origin server, a copy is stored in the web caches for a set period of time. If another user requests the same content again, the web caches sends the stored content and user request doesn't have to be forward to origin server again.

Web-cache flow:

1. A user access a website.

2. A browser sends an HTTP request to the web cache.

    i) If the requested object is stored in cache, the web cache responds with object.

    ii) If the requested object is not stored in cache, the web cache request the object from origin server and sends the response to the browser.

AI Generated Answer

AI is thinking...

5.  Explain the SMTP with example.

5 marks
Details
Official Answer

Simple Mail Transfer Protocol (SMTP) is an Internet standard for electronic mail (email) transmission across Internet Protocol (IP) networks. SMTP (Simple Mail Transfer Protocol) is a TCP/IP protocol used in sending and receiving e-mail. However, since it is limited in its ability to queue messages at the receiving end, it is usually used with one of two other protocols, POP3 or IMAP, that let the user save messages in a server mailbox and download them periodically from the server. In other words, users typically use a program that uses SMTP for sending e-mail and either POP3 or IMAP for receiving e-mail. On Unix-based systems, send mail is the most widely-used SMTP server for e-mail. A commercial package, Send mail, includes a POP3 server. Microsoft Exchange includes an SMTP server and can also be set up to include POP3 support.

SMTP usually is implemented to operate over Internet port 25. An alternative to SMTP that is widely used in Europe is X.400. Many mail servers now support Extended Simple Mail Transfer Protocol (ESMTP), which allows multimedia files to be delivered as e-mail.

An SMTP server performs two functions:

  • Verifies proper configuration and grants permission to a computer attempting to send a message.
  • Sends an outgoing message to a predefined destination and tracks the successful delivery of the message. If it is not deliverable, a message is sent back to the sender. All SMTP servers use their own code which identifies them. For instance, if you are using Hotmail to send e-mail. You would need to configure a mail client, such as Outlook Express with the following code: smtp.hotmail.com
AI Generated Answer

AI is thinking...

5.  Write short notes on various services offered by the Internet.

5 marks
Details
Official Answer

The Internet is a global system of interconnected computer networks that use the standard Internet protocol suite (often called TCP/IP, although not all applications use TCP) to serve billions of users worldwide. It is a network of networks that consists of millions of private, public, academic, business, and government networks, of local to global scope, that are linked by a broad array of electronic, wireless and optical networking technologies. The Internet carries an extensive range of information resources and services, such as the inter-linked hypertext documents of the World Wide Web (WWW) and the infrastructure to support email.

The Internet can:

  • Exchange electronic mail (e-mail) to any Internet user in any location on the planet.
  • Participate in off-line (indirectly, not in real time) discussions via e-mail with people with similar interests through 'mailing lists' and 'News Groups'.
  • Participate live (in real time) in a conversation with another person via the 'Internet video phone' (like Skype), or audio-video conferencing between multiple people using a specially designed computer programs and equipment.
  • Participate in on-line (directly, in real time) written discussion with a larger group of people who use the 'Internet Relay Chat' (IRC) service - chat rooms.
  • To work on a remote computer using the 'Telnet' service or some per function quite the same.
  • Take files of any type (download) from remote computers and deliver files (upload) them with an FTP (File Transfer Protocol) service.
  • Reading complex documents using 'hypertext'. Clicking on a keyword or image on the screen the user is automatically goes to other facilities within the same or other domains.
  • Read multimedia documents found on WWW (World Wide Web) that contain text, graphics, sound, and video using intelligent browser web presentation, as 'Google Chrome', 'Firefox' or 'Internet Explorer' program support.
  • Learning and practicing for the exam and achieve appropriate certification.
  • Search the Web, documents, various WWW sites or via dedicated international service, as 'Google' and 'Yahoo!', over subscribed keywords to find the desired documents.
  • Publicly disclose their images or pictures of his grandchildren, and who wants to can publish a picture of mother in law.
  • Advertise your business in a variety of ways, from setting up video clips to the creation of their own website.
  • Paying bills through the 'Internet Banking'.
  • Buy and spend money : advertise and offer for sale.
  • Read web editions of newspapers or say 'IT Alphabet'.
AI Generated Answer

AI is thinking...

6.  What are the different types of headers in an HTTP message from a client? Explain.

5 marks
Details
Official Answer

HTTP header fields provide required information about the request or response, or about the object sent in the message body. There are four types of HTTP message headers:

  • General-header: These header fields have general applicability for both request and response messages.
  • Request-header: These header fields have applicability only for request messages.
  • Response-header: These header fields have applicability only for response messages.
  • Entity-header: These header fields define meta information about the entity-body or, if no body is present, about the resource identified by the request.

All the above mentioned headers follow the same generic format and each of the header field consists of a name followed by a colon (:) and the field value as follows:

    message-header = field-name ":" [ field-value ]

AI Generated Answer

AI is thinking...

6.  What is the functionality and purpose of HTTP?

5 marks
Details
Official Answer

HTTP is a TCP/IP based communication protocol, that is used to deliver data (HTML files, image files, query results, etc.) on the World Wide Web. The default port is TCP 80, but other ports can be used as well. It provides a standardized way for computers to communicate with each other. HTTP specification specifies how clients' request data will be constructed and sent to the server, and how the servers respond to these requests.

There are three important features of HTTP:

  • HTTP is connectionless: After a request is made, the client disconnects from the server and waits for a response. The server must re-establish the connection after it processes the request.
  • HTTP is media independent: Any type of data can be sent by HTTP as long as both the client and server know how to handle the data content. How content is handled is determined by the MIME specification.
  • HTTP is stateless: This is a direct result of HTTP's being connectionless. The server and client are aware of each other only during a request. Afterwards, each forgets the other. For this reason neither the client nor the browser can retain information between different requests across the web pages.

The following diagram shows a very basic architecture of a web application and depicts where HTTP sits:

HTTP Architecture

The HTTP protocol is a request/response protocol based on the client/server based architecture where web browsers, robots and search engines, etc. act like HTTP clients, and the Web server acts as a server.

Client:

The HTTP client sends a request to the server in the form of a request method, URI, and protocol version, followed by a MIME-like message containing request modifiers, client information, and possible body content over a TCP/IP connection.

Server:

The HTTP server responds with a status line, including the message's protocol version and a success or error code, followed by a MIME-like message containing server information, entity meta information, and possible entity-body content.

AI Generated Answer

AI is thinking...

4. What is HTTP protocol? Define HTTP Request and Response.[2+3]

5 marks
Details
Official Answer

HTTP is a TCP/IP based communication protocol, that is used to deliver data (HTML files, image files, query results, etc.) on the World Wide Web. The default port is TCP 80, but other ports can be used as well. It provides a standardized way for computers to communicate with each other. HTTP specification specifies how clients' request data will be constructed and sent to the server, and how the servers respond to these requests.

HTTP Architecture

HTTP works as a request-response protocol between a client and server. For example: A client (browser) sends an HTTP request to the server; then the server returns a response to the client. The response contains status information about the request and may also contain the requested content.



  • HTTP Request: HTTP client sends an HTTP Request to the HTTP Server according to the HTTP standard, specifying the information the client like to retrieve from the Hypertext Transfer Protocol (HTTP) Server.
  • HTTP Response: Once the HTTP Request arrived at the HTTP server, it will process the request and creates an HTTP Response message. The HTTP response message may contain the resource the HTTP Client requested or information why the HTTP request failed.
AI Generated Answer

AI is thinking...

8.  Explain the client/server concepts of web.

5 marks
Details
Official Answer

Client-server is a computer model that separates client and server, and usually interlinked using a computer network. Each instance of a client can send data requests to one of the servers online and expect a response. In turn, some of the available servers can accept these requests, process them and return the result to the client. Often clients and servers communicate through a computer network with separate hardware, but the client and server can reside on the same system. The machine is a host server that is running one or more server programs that share their resources with clients. A client does not share its resources, but requests content from a server or service function. Clients, therefore, initiate communication sessions with the servers that wait for incoming requests.

AI Generated Answer

AI is thinking...

8.  Describe HTTP with its header fields.

5 marks
Details
Official Answer

HTTP is a TCP/IP based communication protocol, that is used to deliver data (HTML files, image files, query results, etc.) on the World Wide Web. The default port is TCP 80, but other ports can be used as well. It provides a standardized way for computers to communicate with each other. HTTP specification specifies how clients' request data will be constructed and sent to the server, and how the servers respond to these requests.

HTTP header fields provide required information about the request or response, or about the object sent in the message body. There are four types of HTTP message headers:

  • General-header: These header fields have general applicability for both request and response messages.
  • Request-header: These header fields have applicability only for request messages.
  • Response-header: These header fields have applicability only for response messages.
  • Entity-header: These header fields define meta information about the entity-body or, if no body is present, about the resource identified by the request.

All the above mentioned headers follow the same generic format and each of the header field consists of a name followed by a colon (:) and the field value as follows:

    message-header = field-name ":" [ field-value ]

AI Generated Answer

AI is thinking...

9. Explain about domain name and domain name system.

5 marks
Details
Official Answer

Domain Name: There is a massive number of websites available in the WWW. It is necessary to have a domain name to make a website visible to the user.  A domain name is a piece of string that helps to identify a website. For example, the domain of this website is “collegenote.pythonanywhere.com”. The domain name contains an extension to represent the type of the website or the company the website belongs too. The .com refers to a global company while .gov represents a government organization. Similarly, .org represents a non-government organization.

Domain Name System(DNS): Devices and services in the WWW use IP addresses. It is not possible for the users to type each IP address. DNS is the solution to this issue. When the user enters the domain in the web browser, the DNS server converts the domain name to the corresponding IP addresses. 

Difference Between Domain and DNS - Pediaa.Com

Fig: DNS

The main difference between domain name and DNS is that the domain name is a piece of string that helps to identify a particular website while the DNS (Domain Name System) is a server that translates the domain to the corresponding IP address to provide the required webpage.
AI Generated Answer

AI is thinking...

9.  Discuss different types of client server architectures.

5 marks
Details
Official Answer

Client server architecture consists of two kinds of computers: clients and servers. Clients are the computers that that do not share any of its resources but requests data and other services from the server computers and server computers provide services to the client computers by responding to client computers requests.

Client/Sever architecture can be of different model based on the number of layers it holds. Some of them are;

1. 2-Tier Architecture

2-tier architecture is used to describe client/server systems where the client requests resources and the server responds directly to the request, using its own resources. This means that the server does not call on another application in order to provide part of the service. It runs the client processes separately from the server processes, usually on a different computer.

Networking: 3-Tier Client/Server Architecture - CCM

2. 3-Tier Architecture

In 3-tier architecture, there is an intermediary level, meaning the architecture is generally split up between:

 A client, i.e. the computer, which requests the resources, equipped with a user interface (usually a web browser) for presentation purposes

– The application server (also called middleware), whose task it is to provide the requested resources, but by calling on another server

– The data server, which provides the application server with the data it requires.

Networking: 3-Tier Client/Server Architecture - CCM

3. N-Tier Architecture (multi-tier)

N-tier architecture (with N more than 3) is really 3 tier architectures in which the middle tier is split up into new tiers. The application tier is broken down into separate parts. These parts are differs from system to system.

 

AI Generated Answer

AI is thinking...

9.  What is FTP?

5 marks
Details
Official Answer

File transfer protocol (FTP) is a set of rules that computers follow for the transferring of files from one system to another over the internet. It is mainly used for transferring the web page files from their creator to the computer that acts as a server for other computers on the internet. It is also used for downloading the files to computer from other servers.

When a user wishes to engage in File transfer, FTP sets up a TCP connection to the target system for the exchange of control messages. These allow used ID and password to be transmitted and allow the user to specify the file and file action desired. Once file transfer is approved, a second TCP connection is set up for data transfer. The file is transferred over the data connection, without the overhead of headers, or control information at the application level. When the transfer is complete, the control connection is used to signal the completion and to accept new file transfer commands.


Fig: Basic model of FTP

AI Generated Answer

AI is thinking...

9.  What is HTTP?

5 marks
Details
Official Answer

HTTP is a TCP/IP based communication protocol, that is used to deliver data (HTML files, image files, query results, etc.) on the World Wide Web. The default port is TCP 80, but other ports can be used as well. It provides a standardized way for computers to communicate with each other. HTTP specification specifies how clients' request data will be constructed and sent to the server, and how the servers respond to these requests.

There are three important features of HTTP:

  • HTTP is connectionless: After a request is made, the client disconnects from the server and waits for a response. The server must re-establish the connection after it processes the request.
  • HTTP is media independent: Any type of data can be sent by HTTP as long as both the client and server know how to handle the data content. How content is handled is determined by the MIME specification.
  • HTTP is stateless: This is a direct result of HTTP's being connectionless. The server and client are aware of each other only during a request. Afterwards, each forgets the other. For this reason neither the client nor the browser can retain information between different requests across the web pages.
AI Generated Answer

AI is thinking...

10.  What is Web server software? Discuss its role on the Internet.

5 marks
Details
Official Answer

Web server is a program or a computer that can provide services to other programs called clients. A web server can contain one or more websites. A web server processes the incoming requests.

  • The primary function of web server is to store, process and deliver web pages to clients. The communication between client and server takes place using the HTTP. Pages delivered are most frequently HTML documents, which ,may include images, style sheets.
  • A web browser initiates the communication by making a request for a specific resources using HTTP and the server responds with the content of that resources or an error message if unable to do so.

Role of web server:

1. Stores and secures website data: In web hosting services, a web server stores all website data and secures it from unauthorized users when it is properly configured.

2. Provides web database access: A web server’s responsibility is to provide access to websites that are hosted. Web hosting service providers own some web servers that are used in variable ways to provide different web hosting services, such as backend database servers.

3. Serve the end user requests: Web servers accept requests from different users connected over the internet and serve them accordingly.

4. Bandwidth controlling to regulate network traffic: It is a feature available in web server to minimize excess network traffic. Web Hosts can set bandwidth values to regulate the rate of data transmission over the internet. This feature avoids the down time caused by high web traffic.

5. Virtual hosting: Virtual Hosting is a type of web hosting service in which a web server is used to host other software based virtual web-servers web sites, data, applications and other services. Virtualized Web servers do possess this feature to provide virtual hosting.

6. Server side web scripting: This feature of web server enables the user to create dynamic web pages. The popular server side scripting languages include Perl, Ruby, Python, PHPandASP etc

AI Generated Answer

AI is thinking...

10.  What is web client? Discuss its role on the internet.

5 marks
Details
Official Answer

A web client is an application program or web browser that communicates with web server using Hypertext transfer protocol. Web client acts as an interface between server and clients, through which messages are sent to web server. It collects the processed data from the web server. E.g. Google chrome, Internet explorer, opera, firefox, safari.

Roles of web client:

  • It acts as an interface between server and client and displays web document to the client.
  • Web client requests the server for the webpages and resources.
  • It sends HTTP requests and get HTTP response.
  • It stores the cookies for different websites.
  • It helps to bookmark the websites.
AI Generated Answer

AI is thinking...

11.  What are the essential features of web browser? Explain.

5 marks
Details
Official Answer

Browsers are software programs that allow you to search and view the many different kinds of information that's available on the World Wide Web.

Essential Features of web browser:

1. The Web browser should be able to look at the Web pages throughout Internet or to connect to various sites to access information, explore resources and have fun.

2. The Web browser must enable you to follow the hyperlinks on a Web and type in a URL for it to follow.

3. Another feature of browser is to have a number of other commands readily available through menus, icons, and buttons.

4. Your browser ought to include an easy way to get on-line help as well as built in links to other resources on the Web that can give you helps or answer your questions.

5. One of the main feature of a browser is to search the information on the current page as well as search the WWW itself.

6. Browser give you the facility to save a Web page in a file on your com pull print a Web page on your computer, and send the contents of a Web page e-Mail to others on the Internet.

7. Few Web browser are complete Internet package, means they come with components like e-Mail client, newsgroup client an HTML composer, telnet client, ftp client, etc.

8. Web browser should be able to handle text, images of the World Wide Web, as well as the hyperlinks to digital video, or other types of information.

9. The most important feature of any browser is ease of use. While all Web browser  are fundamentally simple to use, the one you settle on should be very easy to work with; it should function as a transparent window onto the Web.

AI Generated Answer

AI is thinking...

11.  Explain briefly, how the domain names are translated to IP addresses.

5 marks
Details
Official Answer
DNS (Domain Name System) is what translate domain name (for eg. www.google.com) into an IP address that our browser can use (for eg. 173.194.35.148). Before the page is loaded, the DNS must be resolved so the browser can establish a TCP connection to make the HTTP request. The DNS Resolution process starts when the user types a URL address on the browser and hits Enter.

The DNS works as follows:
  1. A user types ‘example.com’ into a web browser and the query travels into the Internet and is received by a DNS recursive resolver.
  2. The resolver then queries a DNS root nameserver (.).
  3. The root server then responds to the resolver with the address of a Top Level Domain (TLD) DNS server (such as .com or .net), which stores the information for its domains. When searching for example.com, our request is pointed toward the .com TLD.
  4. The resolver then makes a request to the .com TLD.
  5. The TLD server then responds with the IP address of the domain’s nameserver, example.com.
  6. Lastly, the recursive resolver sends a query to the domain’s nameserver.
  7. The IP address for example.com is then returned to the resolver from the nameserver.
  8. The DNS resolver then responds to the web browser with the IP address of the domain requested initially.
  9. Once the 8 steps of the DNS lookup have returned the IP address for example.com, the browser is able to make the request for the web page:

  10. The browser makes a HTTP request to the IP address.
  11. The server at that IP returns the webpage to be rendered in the browser (step 10).
AI Generated Answer

AI is thinking...

12.  Explain the client/server concepts of web.

5 marks
Details
Official Answer

Client-server is a computer model that separates client and server, and usually interlinked using a computer network. Each instance of a client can send data requests to one of the servers online and expect a response. In turn, some of the available servers can accept these requests, process them and return the result to the client. Often clients and servers communicate through a computer network with separate hardware, but the client and server can reside on the same system. The machine is a host server that is running one or more server programs that share their resources with clients. A client does not share its resources, but requests content from a server or service function. Clients, therefore, initiate communication sessions with the servers that wait for incoming requests.

AI Generated Answer

AI is thinking...

12.  Differentiate between domain name and domain name system.

5 marks
Details
Official Answer

Domain Name: There is a massive number of websites available in the WWW. It is necessary to have a domain name to make a website visible to the user.  A domain name is a piece of string that helps to identify a website. For example, the domain of this website is “collegenote.pythonanywhere.com”. The domain name contains an extension to represent the type of the website or the company the website belongs too. The .com refers to a global company while .gov represents a government organization. Similarly, .org represents a non-government organization.

Domain Name System(DNS): Devices and services in the WWW use IP addresses. It is not possible for the users to type each IP address. DNS is the solution to this issue. When the user enters the domain in the web browser, the DNS server converts the domain name to the corresponding IP addresses. 

Difference Between Domain and DNS - Pediaa.Com

Fig: DNS

The main difference between domain name and DNS is that the domain name is a piece of string that helps to identify a particular website while the DNS (Domain Name System) is a server that translates the domain to the corresponding IP address to provide the required webpage.
AI Generated Answer

AI is thinking...

12.  Describe the significance of IP addresses and their types.

5 marks
Details
Official Answer

An Internet Protocol address (IP address) is a numerical label assigned to each device connected to a computer network that uses the Internet Protocol for communication. An IP address provides an identity to a networked device. Similar to a home or business address supplying that specific physical location with an identifiable address, devices on a network are differentiated from one another through IP addresses.

There are following types of II address. Private IP Address , Public IP Address , Static IP Address , Dynamic IP Address

Private IP Address:  A private IP address is an IP address which is communicate within the same network. Devices with a private IP address cannot to the internet directly. Likewise, computer or the other devices outside the local network cannot connect directly to a devices with a private IP address.

Public IP Address: A public IP address is an IP address which is used to communicate outside the network and each IP address is unique. The public IP address is assigned to the device by the internet service provider (ISP) as soon as the device is connected to the internet.

Static IP Address: A static IP address are those type of IP address that never change once they are assigned to a device on a network.

Dynamic IP Address: The dynamic IP address are those type of IP address that can change from time-to-time. These IP address are assigned to a device when they get connected to the internet each time.

AI Generated Answer

AI is thinking...

13.  Write short notes on:

        a)       SMTP

        b)       XQuery

5 marks
Details
Official Answer

a. SMTP

Simple Mail Transfer Protocol (SMTP) is an Internet standard for electronic mail (email) transmission across Internet Protocol (IP) networks. SMTP (Simple Mail Transfer Protocol) is a TCP/IP protocol used in sending and receiving e-mail. However, since it is limited in its ability to queue messages at the receiving end, it is usually used with one of two other protocols, POP3 or IMAP, that let the user save messages in a server mailbox and download them periodically from the server. In other words, users typically use a program that uses SMTP for sending e-mail and either POP3 or IMAP for receiving e-mail. On Unix-based systems, send mail is the most widely-used SMTP server for e-mail. A commercial package, Send mail, includes a POP3 server. Microsoft Exchange includes an SMTP server and can also be set up to include POP3 support.

SMTP usually is implemented to operate over Internet port 25. An alternative to SMTP that is widely used in Europe is X.400. Many mail servers now support Extended Simple Mail Transfer Protocol (ESMTP), which allows multimedia files to be delivered as e-mail.

An SMTP server performs two functions:

  • Verifies proper configuration and grants permission to a computer attempting to send a message.
  • Sends an outgoing message to a predefined destination and tracks the successful delivery of the message. If it is not deliverable, a message is sent back to the sender. All SMTP servers use their own code which identifies them. For instance, if you are using Hotmail to send e-mail. You would need to configure a mail client, such as Outlook Express with the following code: smtp.hotmail.com

b.  XQuery

XQuery is a functional query language used to retrieve information stored in XML format. It is same as for XML what SQL is for databases. It was designed to query XML data.

XQuery is built on XPath expressions. It is a W3C recommendation which is supported by all major databases.

E.g.

for $x in doc("books.xml")/bookstore/book
where $x/price>30
order by $x/title
return $x/title

AI Generated Answer

AI is thinking...

Unit 2: Hyper Text Markup Language
20 Questions

1. Explain the structure of HTML file with example. How is HTML different from CSS? Explain three different ways for inserting CSS code into an HTML file.

10 marks
Details
Official Answer

HTML (Hyper Text Markup Language) is the standard markup language for creating Web pages. It describes the structure of a Web page.

Structure of HTML document

Every HTML document consists of four basic structure elements: html, head, title, and body. Each of these is explored in detail below:

1. Html Element

  • Start tag: <html> - First tag in the document which declares you are writing an HTML element.
  • End tag: </html> - Last tag in the document.

2. Head Element

  • Start tag: <head> - Second tag, follows the <html> tag, and starts the head section, which describes the document.
  • End tag: </head> - Fifth tag, follows the </title> tag and closes the head section.

3. Title Element

  • Start tag: <title> - Third tag, follows the <head> tag, and contains the title you want for the document. This information will be displayed in the title bar at the top of the browser window.
  • End tag: </title> - Fourth tag, immediately follows, without any spaces, the title you want for the document and precedes the </head> tag.

4. Body Element

  • Start tag: <body> - Sixth tag, follows the </head> tag to denote starting the content of the document.
  • End tag: </body> - Next to last tag in the document, follows the end of the document content and precedes the </html> tag. 

E.g. 

<!DOCTYPE html>

<html>

<head>

    <title>Page Title</title>

</head>

<body>

    <h1>My First Heading</h1>

    <p>My first paragraph.</p>

</body>

</html>

Difference Between HTML and CSS

1. HTML is the basic markup language which describes the content and structure of the web pages. On the other hand, CSS is the extension to the HTML which modifies the design and display of the web pages.

2. HTML file can contain CSS code while CSS stylesheets can never contain HTML code in it.

3. HTML comprises of tags surrounding content. Whereas CSS comprised of selectors succeeded by a declaration block. 

Ways for inserting CSS code into an HTML file

1. Inline CSS

  • An inline CSS is used to apply a unique style to a single HTML element.
  • An inline CSS uses the style attribute of an HTML element.
The following example sets the text color of the <h1> element to blue:
    <h1 style="color:blue;">A Blue Heading</h1>

2. Internal CSS
  • An internal CSS is used to define a style for a single HTML page.
  • An internal CSS is defined in the <head> section of an HTML page, within a <style> element.
E.g.
<!DOCTYPE html>
<html>
<head>
<style>
    body{background-color: powderblue;}
    h1{color: blue;}
    p{color: red;}
</style>
</head>
<body>
    <h1>This is a heading</h1>
    <p>This is a paragraph.</p>
</body>
</html>

3. External CSS
  • An external style sheet is used to define the style for many HTML pages.
  • To use an external style sheet, add a link to it in the <head> section of each HTML page.
E.g.
<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
    <h1>This is a heading</h1>
    <p>This is a paragraph.</p>
</body>
</html>

//style.css
body {
  background-color: powderblue;
}
h1 {
  color: blue;
}
p {
  color: red;
}
AI Generated Answer

AI is thinking...

2.  Define DTD. What are its applications? Create the HTML document with the paragraph using <p>,<h1>, <strong> for the first word for every sentence and <em> for all the capital letters.

10 marks
Details
Official Answer

DTD (Document Type Definition) defines the legal building blocks of an XML documents. It is used to define document structure with a list of legal elements and attributes. DTD can be classified on its declaration basis in the XML document, such as −

  • Internal DTD: A DTD is referred to as an internal DTD if elements are declared within the XML file.
  • External DTD: A DTD is referred to as an external DTD if elements are declared outside the XML file.

Application:

  • With a DTD, independent groups of people can agree on a standard DTD for interchanging data.
  • An application can use a DTD to verify that XML data is valid.

Now, 

<!DOCTYPE html>

<html>

 <head>

    <title>Nepal</title>

 </head>

 <body>

    <h1>My Country Nepal</h1>

    <p><strong><em>M</em>y</strong> country <em>N</em>epal is situated between two large countries <em>C</em>hina and <em>I</em>ndia <br />

    <strong><em>I</em>t</strong> is well known for it cultural diversity.<br/>

    <strong><em>P</em>eople</strong> around the world visit <em>N</em>epal for tourism.<br/>

  <strong><em>N</em>pal</strong>is agro-based country.<strong><em>S</em>ixty</strong> five percentage people completely depend on agriculture in <em>N</em>epal.</p>

 </body>

</html> 

AI Generated Answer

AI is thinking...

3.  Using test structuring toys, create a homepage for the curriculum vitae. Save at web server that is local or on the internet. Later view it using the browser.

10 marks
Details
Official Answer

<!DOCTYPE html>

 <html>

 <head>

 <title>Curriculum Vitae</title>

 </head>

 <body>

    <form id="form1" runat="server">

    <h1>Curriculum Vitae</h1>

    <div>

    <br />

    <table style="width:100%;">

    <tr>

        <td>Name:</td>

        <td>Manish Poudel</td>

    </tr>

    <tr>

        <td>Father Name</td>

        <td>Binod Poudel</td>

    </tr>

     <tr>

         <td>DOB:</td>

         <td>12<sup>th</sup> OCT 1998</td>

    </tr>

    <tr>

        <td>Temporary Address:</td>

        <td>Kathmandu</td>

    </tr>

    <tr>

        <td>Permanent Address</td>

        <td>Ramechhap</td>

    </tr>

    <tr>

        <td>Marital Status</td>

        <td>Unmarried</td>

    </tr>

    <tr>

        <td>&nbsp;</td>

        <td>&nbsp;</td>

    </tr>

    </table>

    </div>

 </form>

    <table style="width:100%;" >

    <tr>

        <td>Educational Information</td>

        <td>&nbsp;</td>

        <td>&nbsp;</td>

    </tr>

    <tr>

        <td>&nbsp;</td>

        <td>&nbsp;</td>

        <td>&nbsp;</td>

    </tr>

    <tr>

        <td>Degree</td>

        <td>Passed Year</td>

        <td>Percentage</td>

    </tr>

    <tr>

        <td>SLC</td>

        <td>2070 B.S.</td>

        <td>83</td>

    </tr>

    <tr>

        <td>+2 </td>

        <td>2073 B.S.</td>

        <td>74</td>

    </tr>

    <tr>

        <td>Bsc. CSIT </td>

        <td>Running</td>

        <td>N/A</td>

    </tr>

 </table>

 <br />

 Achievements:<br />

 <ul>

    <li>First Prize on Graphic Design in INFOTEC Festival</li>

    <li>Second Prize on On spot Software Development Inter college Competition</li>

    <li>Second Prize in Swimming Competition Olympic 2014</li>

 </ul>

 </body>

</html>


Let’s save in E: drive by named cv.html.

Viewing CV in Browser

Just Type in Browser address bar : file:///E:/cv.html

AI Generated Answer

AI is thinking...

4.  What is the structure of HTML file? Explain with example.

5 marks
Details
Official Answer

HTML (Hyper Text Markup Language) is the standard markup language for creating Web pages. It describes the structure of a Web page.

Structure of HTML document

Every HTML document consists of four basic structure elements: html, head, title, and body. Each of these is explored in detail below:

1. Html Element

  • Start tag: <html> - First tag in the document which declares you are writing an HTML element.
  • End tag: </html> - Last tag in the document.

2. Head Element

  • Start tag: <head> - Second tag, follows the <html> tag, and starts the head section, which describes the document.
  • End tag: </head> - Fifth tag, follows the </title> tag and closes the head section.

3. Title Element

  • Start tag: <title> - Third tag, follows the <head> tag, and contains the title you want for the document. This information will be displayed in the title bar at the top of the browser window.
  • End tag: </title> - Fourth tag, immediately follows, without any spaces, the title you want for the document and precedes the </head> tag.

4. Body Element

  • Start tag: <body> - Sixth tag, follows the </head> tag to denote starting the content of the document.
  • End tag: </body> - Next to last tag in the document, follows the end of the document content and precedes the </html> tag. 

E.g. 

<!DOCTYPE html>

<html>

<head>

    <title>Page Title</title>

</head>

<body>

    <h1>My First Heading</h1>

    <p>My first paragraph.</p>

</body>

</html>

AI Generated Answer

AI is thinking...

4.  What is HTML? Differentiate between "get" and "post" methods used to send form data.

5 marks
Details
Official Answer

HTML (Hyper Text Markup Language) is the standard markup language for creating Web pages. It describes the structure of a Web page.

Difference between GET and POST method

GET methodPOST method
GET is used to request data from a specified resource.POST is used to send data to a server to create/update a resource.
Data is visible to everyone in the URL.Data is not displayed in the URL.
Parameters remain in browser history.Parameters are not saved in browser history.
GET request can be cached.POST requests are never cached.
GET request can be bookmarked.POST requests cannot be bookmarked.
GET is less secure compared to POST because data is visible in the URL.POST is a litter safer than GET because the parameters are not saved in browser history.
GET request may have length restrictions.POST requests have no restriction on data length.
GET method should not be used when sending passwords or sensitive information.POST method used when sending password or other sensitive information.
Only ASCII characters are allowed.No restrictions. Binary data is also allowed.
AI Generated Answer

AI is thinking...

4.  What are the tags and attributes for a table in HTML document?

4 marks
Details
Official Answer

Tables are defined with the <table> tag. A table is divided into rows (with the <tr> tag), and each row is divided into data cells (with the <td> tag). The letters td stands for "table data," which is the content of a data cell. A data cell can contain text, images, lists, paragraphs, forms, horizontal rules, tables, etc. Headings in a table are defined with <th> tag.

Table tags:

Table tags attributes:

E.g.

<!DOCTYPE html>

<html>

<head>

<title>Table</title>

</head>

<body>

<h1>The table element</h1>

<table border="1">

  <tr>

    <th>Month</th>

    <th>Savings</th>

  </tr>

  <tr>

    <td>January</td>

    <td>$100</td>

  </tr>

  <tr>

    <td>February</td>

    <td>$80</td>

  </tr>

</table>

</body>

</html>

AI Generated Answer

AI is thinking...

5. Write a HTML script to insert audio file in a HTML page? Use the controls and autoplay properties.

5 marks
Details
Official Answer

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Audio</title>

</head>

<body>

    <audio controls autoplay>

        <source src="audio.mp3" type="audio/mpeg">

      Your browser does not support the audio element.

    </audio>

</body>

</html>

AI Generated Answer

AI is thinking...

5.  Discuss the structure of HTML document with suitable example.

5 marks
Details
Official Answer

HTML (Hyper Text Markup Language) is the standard markup language for creating Web pages. It describes the structure of a Web page.

Structure of HTML document

Every HTML document consists of four basic structure elements: html, head, title, and body. Each of these is explored in detail below:

1. Html Element

  • Start tag: <html> - First tag in the document which declares you are writing an HTML element.
  • End tag: </html> - Last tag in the document.

2. Head Element

  • Start tag: <head> - Second tag, follows the <html> tag, and starts the head section, which describes the document.
  • End tag: </head> - Fifth tag, follows the </title> tag and closes the head section.

3. Title Element

  • Start tag: <title> - Third tag, follows the <head> tag, and contains the title you want for the document. This information will be displayed in the title bar at the top of the browser window.
  • End tag: </title> - Fourth tag, immediately follows, without any spaces, the title you want for the document and precedes the </head> tag.

4. Body Element

  • Start tag: <body> - Sixth tag, follows the </head> tag to denote starting the content of the document.
  • End tag: </body> - Next to last tag in the document, follows the end of the document content and precedes the </html> tag. 

E.g. 

<!DOCTYPE html>

<html>

<head>

    <title>Page Title</title>

</head>

<body>

    <h1>My First Heading</h1>

    <p>My first paragraph.</p>

</body>

</html>

AI Generated Answer

AI is thinking...

5.  How can you draw a table in HTML? Discuss with suitable example.

5 marks
Details
Official Answer

Tables are defined with the <table> tag. A table is divided into rows (with the <tr> tag), and each row is divided into data cells (with the <td> tag). The letters td stands for "table data," which is the content of a data cell. A data cell can contain text, images, lists, paragraphs, forms, horizontal rules, tables, etc. Headings in a table are defined with <th> tag.

Table tags:

Table tags attributes:

E.g.

<!DOCTYPE html>

<html>

<head>

<title>Table</title>

</head>

<body>

<h1>The table element</h1>

<table border="1">

  <tr>

    <th>Month</th>

    <th>Savings</th>

  </tr>

  <tr>

    <td>January</td>

    <td>$100</td>

  </tr>

  <tr>

    <td>February</td>

    <td>$80</td>

  </tr>

</table>

</body>

</html>

AI Generated Answer

AI is thinking...

5.  Write and HTML code to display a simple form for user login.

5 marks
Details
Official Answer

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Login Form</title>

</head>

<body>

    <h2>Login Form</h2>

    <form name="loginForm" method="POST" action="">

        <div>

            <label for="username">Please enter your username: </label>

            <input type="text" name="username" id="username">

        </div>

        <div>

            <label for="password">Please enter your password: </label>

            <input type="password" name="password" id="password">

        </div>

        <div>

            <input type="submit" name="login" value="login">

        </div>

    </form>

</body>

</html>

AI Generated Answer

AI is thinking...

6.  Write and HTML code to display the following:

                                

5 marks
Details
Official Answer

<!DOCTYPE html>

<html>

<head>

<title>Example</title>

</head>

<body>

 <table border="1">

  <tr>

<td><b>Example</b></td>

  </tr>

  <tr>

<td>(a+b)<sup>2</sup>=a<sup>2</sup>+ 2ab + b<sup>2</sup></td>

  </tr>

  <tr>

<td>Thank You</td>

  </tr>

 </table>

</body>

</html>

AI Generated Answer

AI is thinking...

6.  Write HTML script for displaying table with following output.

 

5 marks
Details
Official Answer

<!DOCTYPE html>

<html>

<head>

<title>Page Title</title>

</head>

<body>

<table border="1">

  <tr>

<th>Drinks</th>

    <th>Snacks</th>

  </tr>

  <tr>

    <td>

     <ol>

    <li>Coke</li>

    <li>Sprite</li>

     </ol>

    </td>

    <td>Momo</td>

  </tr>

  <tr>

    <td>

     <ul>

    <li>Milk</li>

    <li>Coffe</li>

     </ul>

    </td>

    <td>Chowmin</td>

  </tr>

</table>

</body>

</html>

AI Generated Answer

AI is thinking...

6.  Write an HTML code to display the following:

                   

5 marks
Details
Official Answer

<!DOCTYPE html>

<html>

<head>

<title>Login Form</title>

    <style>

        #form1{border: 1px solid; padding: 20px; width: 300px;}

    </style>

</head>

<body>

<form id="form1">

<label>Username:</label>

<input id="txtUserName" type="text" /><br /><br />

<label>Password:</label>

<input id="txtPassword" type="text" /><br /><br />

<input type="button" value="Login" />

</form>

</body>

</html>

AI Generated Answer

AI is thinking...

6.  What are the color attributes in HTML? Explain.

5 marks
Details
Official Answer

Colors are very important to give a good look and feel to your website. We can specify colors on page level using <body> tag or you can set colors for individual tags using bgcolor attribute.

The <body> tag has following attributes which can be used to set different colors −

  • bgcolor − sets a color for the background of the page.
  • text − sets a color for the body text.
  • alink − sets a color for active links or selected links.
  • link − sets a color for linked text.
  • vlink − sets a color for visited links − that is, for linked text that you have already clicked on.

There are following three different methods to set colors in your web page −

  • Color names − We can specify color names directly like green, blue or red.
  • Hex codes − A six-digit code representing the amount of red, green, and blue that makes up the color.
  • Color decimal or percentage values − This value is specified using the rgb( ) property.

E.g. 

<!DOCTYPE html>

<html>

   <head>

      <title>HTML Colors by Name</title>

   </head>

   <body text = "blue" bgcolor = "green">

      <p>Use different color names for for body and table and see the result.</p>

      <table bgcolor = "black">

         <tr>

            <td>

               <font color = "white">This text will appear white on black background.</font>

            </td>

         </tr>

      </table>

   </body>

</html>

AI Generated Answer

AI is thinking...

6.  Write an HTML code to display the following:

ID

Name

Address

Age

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

5 marks
Details
Official Answer

<!DOCTYPE html>

<html>

<head>

<title>Table</title>

</head>

<body>

 <table border="1" width="100%">

 <tr>

    <th>ID</th>

    <th>Name</th>

    <th>Address</th>

    <th>Age</th>

  </tr>

  <tr>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

  </tr>

  <tr>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

  </tr>

  <tr>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

  </tr>

  <tr>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

  </tr>

  <tr>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

  </tr>

  <tr>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

  </tr>

 </table>

</body>

</html>

AI Generated Answer

AI is thinking...

7.  What are the attributes of list tag? Explain.

5 marks
Details
Official Answer

HTML supports ordered, unordered and definition lists.

  • <ul> − An unordered list. This will list items using plain bullets.
  • <ol> − An ordered list. This will use different schemes of numbers to list your items.
  • <dl> − A definition list. This arranges your items in the same way as they are arranged in a dictionary.

By default, unorder list will list the items with it disc. We can use type attribute for <ul> tag to specify the type of bullet we like. Following are the possible options −

  • <ul type = "square">
  • <ul type = "disc">
  • <ul type = "circle">
E.g. 
<!DOCTYPE html>
<html>
   <head>
      <title>HTML Unordered List</title>
   </head>
   <body>
      <ul type = "square">
         <li>Ginger</li>
         <li>Potato</li>
         <li>Radish</li>
      </ul>
   </body>
</html>

In ordered list we can use type attribute for <ol> tag to specify the type of numbering we like. By default, it is a number. Following are the possible options −
  • <ol type = "1"> - Default-Case Numerals.
  • <ol type = "I"> - Upper-Case Numerals.
  • <ol type = "i"> - Lower-Case Numerals.
  • <ol type = "A"> - Upper-Case Letters.
  • <ol type = "a"> - Lower-Case Letters.
E.g. 
<!DOCTYPE html>
<html>
   <head>
      <title>HTML Ordered List</title>
   </head>
   <body>
      <ol type = "A">
         <li>Ginger</li>
         <li>Potato</li>
         <li>Radish</li>
      </ol>
   </body>
</html>
AI Generated Answer

AI is thinking...

7.  What are the visibility and display properties of HTML elements? Explain with example.

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

5. Create a HTML page with tags header, article and footer. Insert alink containing mail to info@iost.edu.np in the footer tag. Set the keywords "iost", "csit" using Meta tag in the page.[5]

5 marks
Details
Official Answer
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="keywords" content="iost, csit">
    <title>IOST</title>
</head>
<body>

    <header style="background-color: darkgray; margin-bottom: 2px;">
        <nav>          
            <a href="#">Home</a>
            <a href="#">About</a>
            <a href="#">Contact</a>  
        </nav>    
    </header>

    <article>
        Institute of Science and Technology (IoST) is one of the oldest and the largest technical institutes in TU.
    </article>

    <footer style="background-color: darkgray; margin-top: 2px; text-align: center;">
        <a href="info@iost.edu.np">Send Email</a>
    </footer>
   
</body>
</html>
AI Generated Answer

AI is thinking...

12. Write HTML script for displaying div with following output. The div should be floating right.



5 marks
Details
Official Answer

<!DOCTYPE html>

<html lang="en">

<head>

    <title>List</title> 

</head>

<body>

    <div class="list" style="float: right; padding-right: 50px; border: 1px solid;">

        <h2>CSIT</h2>

        <ol>

            <li>PMC</li>

            <li>BMC</li>

        </ol>

        <h2>BCA</h2>

        <ul>

            <li>TC</li>

            <li>PPL</li>

        </ul>

    </div>

</body>

</html>

AI Generated Answer

AI is thinking...

12. Why inline frames are used? Create a HTML page containing iframe within a paragraph. The iframe have source to http://www.tuiost.edu.np and its height and width are 200px and 400px respectively.[1+4]

5 marks
Details
Official Answer

An inline frame is used to embed another document within the current HTML document. The HTML <iframe> tag specifies an inline frame.

    Syntax: <iframe src="url" title="description"></iframe>


index.html

<!DOCTYPE html>
<html>
<head>
    <title>TU</title>
</head>
<body>
  <p>
    Institute of Science and Technology (IoST) is one of the oldest and the largest technical institutes in TU with 13
Central Departments,1 School, 24 constituent campuses and 89 affiliated campuses. For more details visit our website:  
    <iframe src = "http://www.tuiost.edu.np" width = "400px" height = "200px" title="tuiost website">
      Sorry your browser does not support inline frames.
    </iframe>
  </p>
</body>
</html>
AI Generated Answer

AI is thinking...

Unit 3: Cascading Style Sheets
13 Questions

4.  Explain with example the basic concept of cascading and inheritance in CSS.

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

4.  How external style sheets can be inserted in a HTML document? Illustrate with example.

5 marks
Details
Official Answer

External CSS contains separate CSS file which contains only style property with the help of tag attributes (For example class, id, heading, … etc). CSS property written in a separate file with .css extension and should be linked to the HTML document using link tag. This means that for each element, style can be set only once and that will be applied across web pages.

E.g. 

<!DOCTYPE html> 

<html> 

    <head> 

        <link rel="stylesheet" href="style.css"/> 

    </head> 

    <body> 

        <div class = "main"> 

            <div class ="CN">College Note</div> 

            <div id ="webtech"> 

                Web tech solution. 

            </div> 

        </div> 

    </body> 

</html> 


//style.css

body {

    background-color:powderblue;

}

.main {

    text-align:center;   

}

.CN {

    color:#009900;

    font-size:50px;

    font-weight:bold;

}

#webtech {

    font-style:bold;

    font-size:20px;

}

AI Generated Answer

AI is thinking...

3. How positioning of HTML elements can be done using CSS? Create a HTML page with a div with some content and two paragraph with some contents having id p1 and p2. Write external CSS for the div tag having fixed position with border style solid and width 2 px. the p1 should have relative position. The font type of p1 should be Arial and color should be red. The p2 have absolute position  with top 0px and left 200px.[2+8]

10 marks
Details
Official Answer

The position property specifies the type of positioning method used for an HTML element. There are four different position values:

  • Static Positioning: Static positioning is the default that every element gets. Static positioned elements are not affected by the top, bottom, left, and right properties.
  • Fixed Positioning: An element with position: fixed; is positioned relative to the viewport, which means it always stays in the same place even if the page is scrolled. The top, right, bottom, and left properties are used to position the element.
  • Relative Positioning: Relative positioning changes the position of the HTML element relative to where it normally appears.  Setting the top, right, bottom, and left properties of a relatively-positioned element will cause it to be adjusted away from its normal position.
  • Absolute Positioning: An element with position: absolute is positioned at the specified coordinates relative to our screen top-left corner. 

Second Part:

index.html

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link rel="stylesheet" href="style.css">

    <title>Collegenote</title>

</head>

<body>

    <div class="cn">

        Collegenote is an educational platform to help IT students in their educational career. 

    </div>

    <p id="p1">

        Collegenote is currently focused on creating contents to help students in their study.

    </p>

    <p id="p2">

        Students of B.Sc. CSIT, BIT and BCA can get updated notes, old questions and solutions for the easy learning.

    </p>

</body>

</html>

style.css

.cn{

        position:fixed;

        border: 2px solid black;

    }

 #p1{

        position: relative;

        font-family: Arial;

        color: red;

    }

 #p2{

        position:absolute;

        top: 0px;

        left: 200px;

    }

AI Generated Answer

AI is thinking...

5.  Define CSS? How can you use an external CSS? Explain.

5 marks
Details
Official Answer

CSS is a language that describes the style of an HTML document. It describes how HTML elements should be displayed.

External CSS contains separate CSS file which contains only style property with the help of tag attributes (For example class, id, heading, … etc). CSS property written in a separate file with .css extension and should be linked to the HTML document using link tag. This means that for each element, style can be set only once and that will be applied across web pages.

E.g. 

<!DOCTYPE html> 

<html> 

    <head> 

        <link rel="stylesheet" href="style.css"/> 

    </head> 

    <body> 

        <div class = "main"> 

            <div class ="CN">College Note</div> 

            <div id ="webtech"> 

                Web tech solution. 

            </div> 

        </div> 

    </body> 

</html> 


//style.css

body {

    background-color:powderblue;

}

.main {

    text-align:center;   

}

.CN {

    color:#009900;

    font-size:50px;

    font-weight:bold;

}

#webtech {

    font-style:bold;

    font-size:20px;

}

AI Generated Answer

AI is thinking...

5.  What is CSS? How can you use an internal CSS? Explain.

5 marks
Details
Official Answer

CSS is a language that describes the style of an HTML document. It describes how HTML elements should be displayed.

Internal CSS

The internal style sheet is used to add a unique style for a single document. It is defined in <head> section of the HTML page inside the <style> tag.

E.g

<!DOCTYPE html>  

<html>  

<head>  

  <style>  

    body {  

        background-color: linen;  

    }  

    h1 {  

        color: red;  

        margin-left: 80px;  

    }   

  </style>  

</head>  

<body>  

    <h1>The internal style sheet is applied on this heading.</h1>  

    <p>This paragraph will not be affected.</p>  

</body>  

</html>  

AI Generated Answer

AI is thinking...

6. What is CSS selector? Compare id selector with class selector.

5 marks
Details
Official Answer

A CSS selector is the part of a CSS rule set that actually selects the content we want to style. In CSS, selectors are used to target the HTML elements on our web pages that we want to style.

E.g.

Introduction to CSS » WebNots

Comparison between id selector and class selector

id selectorclass selector
A selector in CSS that styles the element with a specified id.A selector in CSS that styles the element with a specified class.

Syntax is:

#id{

       css declarations;

    }

Syntax is:

.class{

       css declarations;

    }

Used to apply styling to one specific element.Used to apply styling to multiple elements.
It is less used.It is most used on several elements.

E.g.

#main {

    background: #000;

    padding: 10px;

    color: #fff;

    width: 100px;

}


<div id="main">

    Welcome

</div>

E.g.

.main {

    background: #000;

    padding: 10px;

    color: #fff;

    width: 100px;

}


<div class="main">

    Welcome

</div>

AI Generated Answer

AI is thinking...

7.  How can you insert inline style sheet in the HTML document? Discuss with example.

5 marks
Details
Official Answer

An inline CSS is used to apply a unique style to a single HTML element. An inline CSS uses the style attribute of an HTML element. To use inline CSS, we use the style attribute in the relevant tag.

E.g.

The following example sets the text color of the <h1> element to blue, and the text color of the <p> element to red:

<!DOCTYPE html>

<html>

<head>

<title>Inline CSS</title>

</head>

<body>

<h1 style="color:blue;">A Blue Heading</h1>

<p style="color:red;">A red paragraph.</p>

</body>

</html>

AI Generated Answer

AI is thinking...

7.  How can you insert internal style sheet in your HTML document? Discuss with example.

5 marks
Details
Official Answer

The internal style sheet is used to add a unique style for a single document. It is defined in <head> section of the HTML page inside the <style> tag.

E.g. 

<!DOCTYPE html>  

<html>  

<head>  

  <style>  

    body {  

        background-color: linen;  

    }  

    h1 {  

        color: red;  

        margin-left: 80px;  

    }   

  </style>  

</head>  

<body>  

    <h1>The internal style sheet is applied on this heading.</h1>  

    <p>This paragraph will not be affected.</p>  

</body>  

</html>  


AI Generated Answer

AI is thinking...

7.  How can you insert external style sheets in your HTML document? Discuss with example.

5 marks
Details
Official Answer

External CSS contains separate CSS file which contains only style property with the help of tag attributes (For example class, id, heading, … etc). CSS property written in a separate file with .css extension and should be linked to the HTML document using link tag. This means that for each element, style can be set only once and that will be applied across web pages.

E.g. 

<!DOCTYPE html> 

<html> 

    <head> 

        <link rel="stylesheet" href="style.css"/> 

    </head> 

    <body> 

        <div class = "main"> 

            <div class ="CN">College Note</div> 

            <div id ="webtech"> 

                Web tech solution. 

            </div> 

        </div> 

    </body> 

</html> 


//style.css

body {

    background-color:powderblue;

}

.main {

    text-align:center;   

}

.CN {

    color:#009900;

    font-size:50px;

    font-weight:bold;

}

#webtech {

    font-style:bold;

    font-size:20px;

}

AI Generated Answer

AI is thinking...

8. Write a HTML script containing use of media query for changing the background-color of html page to black if the viewport is 600 pixels wide or more than that otherwise if the viewport is less than 500 pixels, the background-color should be changed to red.

5 marks
Details
Official Answer

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Changing Background</title>

    <style>

        @media screen and (max-width: 499px){

            body{

                background-color: red;

            }

        }

        @media screen and (min-width: 600px){

            body{

                background-color: black;

            }

        }

    </style>

</head>

<body>

<p> Body part of the HTML </p> 

</body>

</html>

AI Generated Answer

AI is thinking...

9.  How XSL is different from CSS? Explain.

5 marks
Details
Official Answer

XSL and CSS are two different languages recommended by the World Wide Web Consortium (W3C). XSL is more powerful and complex than CSS. Some of the difference between CSS and XSL are listed below:

  • XSL uses the XML notation that is helpful in writing the codes and the tools are provided in greater extent, whereas CSS doesn’t use any of the XML notations but has its own. 
  • XSL is having the formatting object tree setup differently from the source tree; whereas CSS is having the source tree and the formatting object tree the same.
  • XSL can’t provide the inheritance of the source tree using the formatting properties, whereas CSS provides the inheritance of the formatting object that is related to the source tree.
  • XSL is not supported by many of the web browsers, whereas CSS can be read by modern web browsers.
  • XSL is used to refer to a family of languages used to transform and render XML documents. CSS is a style sheet language used for describing the presentation semantics (the look and formatting) of a document written in a markup language.
  • XSL is designed to meet the needs of more complex applications for richer style sheets, whereas CSS is highly effective and easy to learn for simple applications.
  • XSL supports decision structures and can calculate quantities or store values in variable, whereas CSS doesn't support decision structures and it cannot calculate quantities or store values in variables.
AI Generated Answer

AI is thinking...

12.  Discuss about normal flow box layout in CSS and also discuss about positioning in CSS.

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

11. How web pages can be made responsive using media queries ? Illustrate with an example.[2+3]

5 marks
Details
Official Answer

CSS Media Queries allow us to create responsive websites that look good on all screen sizes, from desktop to mobile. It uses the @media rule to include a block of CSS properties only if a certain condition is true. A media query consists of a media type and can contain one or more expressions, which resolve to either true or false.

        @media not|only mediatype and (expressions{
  
        CSS-Code;
        }

The result of the query is true if the specified media type matches the type of device the document is being displayed on and all expressions in the media query are true. When a media query is true, the corresponding style sheet or style rules are applied, following the normal cascading rules. 

Example:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
.wrapper {overflow: auto;}
.menuitem {
  border: 1px solid #d4d4d4;
  list-style-type: none;
  margin: 4px;
  padding: 2px;
}
@media screen and (min-width: 480px) {
  #leftsidebar {width: 200px; float: left;}
  #main {margin-left: 216px;}
}
</style>
</head>
<body>
<div class="wrapper">
  <div id="leftsidebar">
    <ul id="menulist">
      <li class="menuitem">Menu-item 1</li>
      <li class="menuitem">Menu-item 2</li>
      <li class="menuitem">Menu-item 3</li>
    </ul>
  </div>
  <div id="main">
    <p>This example shows a menu that will float to the left of the page if the viewport is 480 pixels wide or wider.
    If the viewport is less than 480 pixels, the menu will be on top of the content.</p>
  </div>
</div>
</body>
</html>
AI Generated Answer

AI is thinking...

Unit 4: Client Side Scripting with JavaScript
22 Questions

1.  Design a form containing text box for username, password field for password, radio button for gender and checkbox for hobbies. Write a program for  client-side validation of the form for the username and password field as required fields, length of username should be 5, the radio button and checkbox should be checked.

10 marks
Details
Official Answer

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Form validation</title>

    <script>

        function validateForm() {

            var username = document.getElementById("username").value;

            var password = document.getElementById("password").value;

            var gender = document.getElementsByName("gender");

            var hobbies = document.getElementsByName("hobbies");

            if (username == "") {

                alert('username is required');

                return false;

            }

            else if (username.length !== 5) {

                alert('username must be 5 characters long');

                return false;

            }

            else if (password == "") {

                alert('password is required');

                return false;

            }

            else if (!(gender[0].checked || gender[1].checked || gender[2].checked)) {

                alert("Please Select Your Gender");

                return false;

            }

            else if (!(hobbies[0].checked || hobbies[1].checked || hobbies[2].checked || hobbies[3].checked)) {

                alert("Please Select Atleast one of you hobby");

                return false;

            }

            return true;

        }

    </script>

</head>

<body>

<h2>Client Side Form Validation Example</h2>

<form method="POST" action="#">

<div>

<label> Username: </label>

<input type="text" name="username" id="username" required>

</div><br>

<div>

<label> Password: </label>

<input type="password" name="password" id="password" required>

</div><br>

<div>

<label> Gender: </label>

<label><input type="radio" value="m" name="gender"> Male </label>

<label><input type="radio" value="f" name="gender"> Female </label>

<label><input type="radio" value="0" name="gender"> Others </label>

</div><br>

<div>

<label> Hobbies: </label>

<label><input type="checkbox" name="hobbies"> Reading </label>

<label><input type="checkbox" name="hobbies"> Writing </label>

<label><input type="checkbox" name="hobbies"> Playing </label>

<label><input type="checkbox" name="hobbies"> Music </label>

</div><br>

<button onclick="validateForm()">Submit</button>

</form>

</body>

</html>

AI Generated Answer

AI is thinking...

2. Write HTML Script for creating a form containing text box for username, password field for password, and checkbox for Education fields. Write a JavaScript function for the validation of the form for all of the fields as required. In addition length of username should at least 4, the password should start with digit and end with $.

10 marks
Details
Official Answer

// index.html

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link rel="stylesheet" href="form.css">

    <title>Form</title>

    <script type="text/javascript" src="validate.js"></script>

</head>

<body>  

    <div class="form">

<h2>Enter Details</h2>

        <form action=" " onsubmit="return validate()">

            User Name: <input id="uname" type="text" name="username" required><br><br>

            Password: <input id="upass" type="password" name="password" required><br><br>

            Education Field: 

            <input type="checkbox" name="field[]" value="csit"> BscCSIT

            <input type="checkbox" name="field[]" value="bca"> BCA

            <input type="checkbox" name="field[]" value="bit"> BIT <br><br>

            <button  type="submit">Submit</button>

        </form>

    </div>

</body>

</html>

// form.css

body{

    margin: 0;

    padding:0;

    background-image: url(form.jpg);

    background-repeat: no-repeat;

    background-size: cover;

}

.form {

padding: 20% 40%; 

}

// validate.js

function validate(){

    var username = document.getElementById('uname');

    if(username.value.trim().length < 4 ){

        username.style.border = "solid 1px red";

        alert("Username Should Be at least 4");

        return false;

    }

    const password = document.getElementById('upass');

    var regx = /[0-9][a-zA-Z0-9]*[a-zA-Z0-9][$]/;

    if(!regx.test(password.value)){

        password.style.border = 'solid 1px red';

        alert("Password should start with digit and end with $");

        return false;

    }

    var education = document.getElementsByName('field[]');

    for(var i=0;i<education.length;i++){

        if(education[i].checked){

           continue;

        }

        alert("Please Select Your educational field.")

        return false;

    }

   return true;

}

AI Generated Answer

AI is thinking...

3.  What is DOM Hierarchy? Explain the use of *, ? and + in defining a DOM element.

10 marks
Details
Official Answer

Every web page resides inside a browser window which can be considered as an object. A Document object represents the HTML document that is displayed in that window. The Document object has various properties that refer to other objects which allow access to and modification of document content.

The way a document content is accessed and modified is called the Document Object Model, or DOM. The Objects are organized in a hierarchy. This hierarchical structure applies to the organization of objects in a Web document.

Here is a simple hierarchy of a few important objects −

DOM HTML tree


*, ? and + are the part of regular expression.

A asterisk(*) indicates that the preceding character should appear zero or more times in the pattern.

  • The pattern fo* can be found in"fd", "fod", "food", "foood" etc.

A questionmark(?) indicates that the preceding character should appear zero or one times in the pattern.

  • The pattern foo? can be found in "food" and "fod" but not "faod".

A plus sign(+) indicates that the preceding character should appear one or more times in the pattern.

  • The pattern fo+ can be found in "fod", "food" and "foood", but not "fd".
AI Generated Answer

AI is thinking...

3.  Design DOM for the time table of your classes in the present semester. Save at web server that is local or on the Internet. Later view it using the browser.

10 marks
Details
Official Answer

Fig: DOM of Time Table of Current Semester

Above diagram is a DOM implementation of Time table of current semester.

For simplicity, we display only on each day.

Lets write real implementation of DOM in XML file

<?xml version="1.0" encoding="utf-8"?>

<Six_Semester>

 <Day>

 <Sunday>

    <Time1>Compiler</Time1>

    <Time2>Software Engineering

    <Time3>Web Technology</Time3

    <Time4>Statistics</Time4>

    <Time5>Project Lab</Time5

 </Sunday>

 <Monday>

    <Time1>Compiler</Time1>

    <Time2>Software Engineering </Time2>

    <Time3>Web Technology</Time3>

    <Time4>Statistics</Time4>

    <Time5>Project Lab</Time5>

 </Monday>

 <Tuesday>

    <Time1>Compiler</Time1>

    <Time2>Software Engineering</Time2>

    <Time3>Web Technology</Time3>

    <Time4>Statistics</Time4>

    <Time5>Project Lab</Time5>

 </Tuesday>

 <Wednesday>

    <Time1>Compiler</Time1>

    <Time2>Software Engineering</Time2>

    <Time3>Web Technology</Time3>

    <Time4>Statistics</Time4>

    <Time5>Project Lab</Time5>

 </Wednesday>

 <Thursday>

    <Time1>Compiler</Time1>

    <Time2>Software Engineering</Time2>

    <Time3>Web Technology</Time3>

    <Time4>Statistics</Time4>

    <Time5>Project Lab</Time5>

 </Thursday>

 <Friday>

    <Time1>Compiler</Time1>

    <Time2>Software Engineering</Time2>

    <Time3>Web Technology</Time3>

    <Time4>Statistics</Time4>

    <Time5>Project Lab</Time5>

 </Friday>

 </Day>

</Six_Semester>


Let’s save in c: drive by named time_table.xml.

Viewing DOM Document in Browser

Just Type in Browser address bar : file:///C:/time_table.xml

AI Generated Answer

AI is thinking...

2. How can you create objects in Javascript? Create a HTML page containing a division with image and its description in paragraph. Write a javascript function to change the value of description in the paragraph during onmouseover and mouseout event on the image.[4+6]

10 marks
Details
Official Answer

A javaScript object is an entity having state and behavior (properties and method). For example: car, pen, bike, chair, glass, keyboard, monitor etc. There are different ways to create new objects:

1. By using object literal: The syntax of creating object using object literal is given below:

        object={property1:value1, property2:value2.....propertyN:valueN}

    Example: const person = { name: 'Nisha', age: 22, hobbies: ['reading', 'singing', 'coding']};

2. By creating instance of Object directly (using new keyword): The syntax of creating object directly is given below:

        objectname = new Object(); 

    Example: const person = new Object ( { name: 'Nisha', age: 22, hobbies: ['reading', 'singing', 'coding']});

3. By using an object constructor (using new keyword): Here, we need to create function with arguments. Each argument value can be assigned in the current object by using this keyword.

    Example: 

    function Person(name, age) {

        this.name = name;

        this.age = age;

    }

    const person = new Person("Nisha", 22);


Second part:

index.html

<!DOCTYPE html>

<html>

<head>

    <title>TU</title>

    <script type="text/javascript" src="web.js"></script>

</head>

<body>

  <div>

    <img src="images/tu.jpg" onmouseover="changeText()" onmouseout="defaultText()">

    <div id="description">

      <p>Department of CSIT, Tribhuvan University</p>

    </div>

  </div>

</body>

</html>

web.js

function changeText()

{

    var display = document.getElementById('description');

    display.innerHTML = "";

    display.innerHTML = "Department of Computer Science and Informtion Technology, TU!! (Changed Text)";

}

function defaultText()

{

    var display = document.getElementById('description');

    display.innerHTML = "";

    display.innerHTML = "Department of CSIT, Tribhuvan University";

}

AI Generated Answer

AI is thinking...

5.  What do you mean by cookie? Write a Javascript code to handle cookie?

5 marks
Details
Official Answer

A cookie is a variable that is stored on the visitor's computer. Cookies let you store user information in web pages.

When a web server has sent a web page to a browser, the connection is shut down, and the server forgets everything about the user. Cookies were invented to solve the problem "how to remember information about the user".

  • When a user visits a web page, his/her name can be stored in a cookie.
  • Next time the user visits the page, the cookie "remembers" his/her name.

Cookies are saved in name-value pairs like:

    username = Ronaldo

When a browser requests a web page from a server, cookies belonging to the page are added to the request. This way the server gets the necessary data to "remember" information about users.

JavaScript Cookies

JavaScript code to set and get a cookie:

<!DOCTYPE html>  

<html>  

<head>  

</head>  

<body>  

<input type="button" value="setCookie" onclick="setCookie()">  

<input type="button" value="getCookie" onclick="getCookie()">  

    <script>  

    function setCookie()  

    {  

        document.cookie="username=Jayanta";  

    }  

    function getCookie()  

    {  

        if(document.cookie.length!=0)  

        {  

        alert(document.cookie);  

        }  

        else  

        {  

        alert("Cookie not available");  

        }  

    }  

    </script>  

</body>  

</html>  

AI Generated Answer

AI is thinking...

5.  What are the two traditional ways of assigning event handlers in DOM? Explain.

5 marks
Details
Official Answer

Event handlers refer to specific, user imitated actions within the webpage, such as the moving of your mouse over a link, the clicking on a link, or submission of a form. 

The 2 traditional ways of assigning event handlers in DOM are: via HTML, or scripting. In both cases, a function or code is attached at the end, which is executed when the handler detects the specified event.

1) Via HTML, using attributes

We can define an event handler directly inside the relevant HTML tag, by embedding it as a attribute. A piece of JavaScript is also included to tell the browser to perform something when the event occurs. For example,

<a href="https://collegenote.pythonanywhere.com/" onMouseover="window.status='Click here for CSIT note';return true" onMouseout="window.status=''">CollegeNote</a>

2) Via scripting

You can also assign and set up event handlers to elements using scripting, and inside your script . This allows for the event handlers to be dynamically set up, without having to mess around with the HTML codes on the page.

When setting up event handlers for an element directly inside your script, the code to execute for the events must be defined inside a function.

E.g.

<a ID="test" href="https://collegenote.pythonanywhere.com/">CollegeNote</a> 

<script type="text/javascript"> 

function changestatus(){

window.status="Click here for CSIT note"

return true

function changebackstatus(){

window.status=''

document.getElementById("test").onmouseover=changestatus

document.getElementById("test").onmouseout=changebackstatus 

</script>

AI Generated Answer

AI is thinking...

6.  How can you define event handler? Write a Javascript to demonstrate event handling. 

5 marks
Details
Official Answer

Event handlers are JavaScript code that are not added inside the <script> tags, but rather, inside the html tags, that execute JavaScript when something happens, such as pressing a button, moving your mouse over a link, submitting a form etc. The basic syntax of these event handlers is:

    name_of_handler="JavaScript code here"

For example:

<a href="http://google.com" onClick="alert('hello!')">Google</a>

When the above link is clicked, the user will first see an alert message before being taken to Google.

Some event handlers used in JavaScript:


JavaScript code to demonstrate event handling:
<html>
   <head>   
      <script type = "text/javascript">
            function sayHello() {
               alert("Hello World")
            }
      </script>      
   </head>
   <body>
      <p>Click the following button and see result</p>      
      <form>
         <input type = "button" onclick = "sayHello()" value = "Say Hello" />
      </form>      
   </body>
</html>
AI Generated Answer

AI is thinking...

6.  Explain about to charge an HTML element with the help of DOM.

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

6.  How can you define event handler? Write a JavaScript to demonstrate event handling.

5 marks
Details
Official Answer

Event handlers are JavaScript code that are not added inside the <script> tags, but rather, inside the html tags, that execute JavaScript when something happens, such as pressing a button, moving your mouse over a link, submitting a form etc. The basic syntax of these event handlers is:

    name_of_handler="JavaScript code here"

For example:

<a href="http://google.com" onClick="alert('hello!')">Google</a>

When the above link is clicked, the user will first see an alert message before being taken to Google.

Some event handlers used in JavaScript:


JavaScript code to demonstrate event handling:
<html>
   <head>   
      <script type = "text/javascript">
            function sayHello() {
               alert("Hello World")
            }
      </script>      
   </head>
   <body>
      <p>Click the following button and see result</p>      
      <form>
         <input type = "button" onclick = "sayHello()" value = "Say Hello" />
      </form>      
   </body>
</html>
AI Generated Answer

AI is thinking...

7.  What are the important uses of cookies? Give some examples.

5 marks
Details
Official Answer

A cookie is a variable that is stored on the visitor's computer. Cookies let you store user information in web pages.

When a web server has sent a web page to a browser, the connection is shut down, and the server forgets everything about the user. Cookies were invented to solve the problem "how to remember information about the user".

  • When a user visits a web page, his/her name can be stored in a cookie.
  • Next time the user visits the page, the cookie "remembers" his/her name.

Cookies are saved in name-value pairs like:

    username = Ronaldo

When a browser requests a web page from a server, cookies belonging to the page are added to the request. This way the server gets the necessary data to "remember" information about users.

JavaScript Cookies

E.g.

JavaScript code to set and get a cookie:

<!DOCTYPE html>  

<html>  

<head>  

</head>  

<body>  

<input type="button" value="setCookie" onclick="setCookie()">  

<input type="button" value="getCookie" onclick="getCookie()">  

    <script>  

    function setCookie()  

    {  

        document.cookie="username=Jayanta";  

    }  

    function getCookie()  

    {  

        if(document.cookie.length!=0)  

        {  

        alert(document.cookie);  

        }  

        else  

        {  

        alert("Cookie not available");  

        }  

    }  

    </script>  

</body>  

</html>  

AI Generated Answer

AI is thinking...

7. Write a JavaScript code to create an array of elements {csit, it, bca, bim}. Display the array in body of HTML.

5 marks
Details
Official Answer

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Display Array Inside Body</title>

</head>

<body>

    <div class="array">


    </div>

    <script>

        var array = ["csit","it","bca","bim"];

        var dispArea = document.getElementsByClassName('array')[0];

        dispArea.innerHTML = array;

    </script>

</body>

</html>

AI Generated Answer

AI is thinking...

8.  Discuss the use of Cookies with suitable example.

5 marks
Details
Official Answer

A cookie is a variable that is stored on the visitor's computer. Cookies let you store user information in web pages.

When a web server has sent a web page to a browser, the connection is shut down, and the server forgets everything about the user. Cookies were invented to solve the problem "how to remember information about the user".

  • When a user visits a web page, his/her name can be stored in a cookie.
  • Next time the user visits the page, the cookie "remembers" his/her name.

Cookies are saved in name-value pairs like:

    username = Ronaldo

When a browser requests a web page from a server, cookies belonging to the page are added to the request. This way the server gets the necessary data to "remember" information about users.

JavaScript Cookies

E.g.

JavaScript code to set and get a cookie:

<!DOCTYPE html>  

<html>  

<head>  

</head>  

<body>  

<input type="button" value="setCookie" onclick="setCookie()">  

<input type="button" value="getCookie" onclick="getCookie()">  

    <script>  

    function setCookie()  

    {  

        document.cookie="username=Jayanta";  

    }  

    function getCookie()  

    {  

        if(document.cookie.length!=0)  

        {  

        alert(document.cookie);  

        }  

        else  

        {  

        alert("Cookie not available");  

        }  

    }  

    </script>  

</body>  

</html>  

AI Generated Answer

AI is thinking...

8.  Write an example of client side script to validate a form.

5 marks
Details
Official Answer

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Form Registration</title>

</head>

<body>

    <h2>Client Side Form Validation</h2>

    <form name="signupForm" onsubmit="return validateForm();" method="POST" action="">

        <div>

            <label for="username">Please enter your username: </label>

            <input type="text" name="username" id="username">

        </div>

        <div>

            <label for="password">Please enter your password: </label>

            <input type="password" name="password" id="password">

        </div>

        <div>

            <label for="email">Please enter your email: </label>

            <input type="email" name="email" id="email">

        </div>

        <div>

            <input type="submit" name="signup" value="Signup">

        </div>

    </form>

    <script>

        function validateForm() {

            if (document.signupForm.username.value == "") {

                alert("Please provide your usernamename!");

                document.signupForm.username.focus();

                return false;

            }

            else if (document.signupForm.password.value == "") {

                alert("Please provide your password!");

                document.signupForm.password.focus();

                return false;

            }

          else if (document.signupForm.password.value.length < 8) {

                alert('Password must be at least 8 digit long');

                document.signupForm.password.focus();

                return false;

            }

            else if (document.signupForm.email.value == "") {

                alert("Please provide your Email!");

                document.signupForm.email.focus();

                return false;

            }

            return true;

        }

    </script>

</body>

</html>

AI Generated Answer

AI is thinking...

8.  Write a simple client side script to set and retrieve cookies.

5 marks
Details
Official Answer

JavaScript code to set and retrieve a cookie:

<!DOCTYPE html>  

<html>  

<head> 

    <title>Cookies</title>

</head>  

<body>  

<input type="button" value="setCookie" onclick="setCookie()">  

<input type="button" value="getCookie" onclick="getCookie()">  

    <script>  

    function setCookie()  

    {  

        document.cookie="username=Jayanta";  

    }  

    function getCookie()  

    {  

        if(document.cookie.length!=0)  

        {  

        alert(document.cookie);  

        }  

        else  

        {  

        alert("Cookie not available");  

        }  

    }  

    </script>  

</body>  

</html>  

AI Generated Answer

AI is thinking...

9.  Write a simple client-side script to set and retrieve cookies.

5 marks
Details
Official Answer

JavaScript code to set and retrieve a cookie:

<!DOCTYPE html>  

<html>  

<head>

    <title>Cookie</title> 

</head>  

<body>  

<input type="button" value="setCookie" onclick="setCookie()">  

<input type="button" value="getCookie" onclick="getCookie()">  

    <script>  

    function setCookie()  

    {  

        document.cookie="username=Jayanta";  

    }  

    function getCookie()  

    {  

        if(document.cookie.length!=0)  

        {  

        alert(document.cookie);  

        }  

        else  

        {  

        alert("Cookie not available");  

        }  

    }  

    </script>  

</body>  

</html>  

AI Generated Answer

AI is thinking...

10. Discuss different types of jQuery Selectors with examples.

5 marks
Details
Official Answer

jQuery selectors allow you to select and manipulate HTML element(s). jQuery selectors are used to "find" (or select) HTML elements based on their name, id, classes, types, attributes, values of attributes and much more. 

All selectors in jQuery start with the dollar sign and parentheses: $().

The different types of jQuery selectors are:

1. The element Selector

The jQuery element selector selects elements based on the element name.

E.g. When a user clicks on a button, all <p> elements will be hidden:

$(document).ready(function(){

  $("button").click(function(){

    $("p").hide();

  });

});

2. The #id Selector

The jQuery #id selector uses the id attribute of an HTML tag to find the specific element. To find an element with a specific id, write a hash character, followed by the id of the HTML element:

E.g. When a user clicks on a button, the element with id="test" will be hidden:

$(document).ready(function(){

  $("button").click(function(){

    $("#test").hide();

  });

});

3. The .class Selector

The jQuery .class selector finds elements with a specific class. To find elements with a specific class, write a period character, followed by the name of the class.

E.g. When a user clicks on a button, the elements with class="test" will be hidden:

$(document).ready(function(){

  $("button").click(function(){

    $(".test").hide();

  });

});

AI Generated Answer

AI is thinking...

6. How jQuery animate can be used to create custom animation? Write syntax with sample script.[2+3]

5 marks
Details
Official Answer

The animate() method performs a custom animation of a set of CSS properties. This method changes an element from one state to another with CSS styles. The CSS property value is changed gradually, to create an animated effect. Only numeric values can be animated (like "margin:30px"). String values cannot be animated (like "background-color:red"), except for the strings "show", "hide" and "toggle".

Syntax:

    $(selector).animate({ properties }, duration, callback);

  • properties parameter defines the CSS properties to be animated.
  • duration parameter is optional and specifies the duration of the effect. It can be set as "slow" , "fast" or milliseconds.
  • callback parameter is also optional and it is a function which is executed after the animation completes.

Example:

<!DOCTYPE html>  
<html>  
<head>  
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>  
<script>  
    $(document).ready(function(){  
        $("button").click(function(){  
            $("div").animate({left: '450px'});  
        });  
    });  
</script>  
</head>  
<body>  
<button>Start Animation</button>  
<div style="background:#98bf21;height:100px;width:100px;position:absolute;"></div>  
</body>  
</html>
AI Generated Answer

AI is thinking...

11.  Explain about client side programming with example?

5 marks
Details
Official Answer
Client-side programming mostly deals with the user interface with which the user interacts in the web. It is mostly a browser, in the user's machine, that runs the code and is mainly done in any scripting language like JavaScript.

Client-side Uses:

  • Makes interactive web pages
  • Make stuff work dynamically
  • Interact with temporary storage
  • Works as an interface between user and server
  • Sends requests to the server
  • Retrieval of data from Server
  • Interact with local storage
  • Provides remote access for client-server program
There are many client-side scripting languages too.
  • JavaScript
  • VBScript
  • HTML (Structure)
  • CSS (Designing)
  • AJAX
  • jQuery etc.

Client-side Example:

// sample HTML code  

<html>  

<head>  

    <title>Client Side </title>  

</head>  

<body>  

    <h1>  

        Hello Guys!!  

    </h1>  

</body>  

</html> 

AI Generated Answer

AI is thinking...

7. What is the use of JSON? How can you parse a JSON, illustrate with an example.[1+4]

5 marks
Details
Official Answer

JavaScript Object Notation (JSON) is a standard text-based format for representing structured data based on JavaScript object syntax. It is commonly used for transmitting data in web applications (e.g., sending some data from the server to the client, so it can be displayed on a web page, or vice versa). 

Structure:

JSON Object diagram

Example:

{

    "name": "Archana",

    "age": 22

}


The JSON.parse() method parses a JSON string, constructing the JavaScript value or object described by the string. 

Syntax: JSON.parse(text);

  •     text is the string to parse as JSON.

Example:

const json = '{"name":"Archana, "age":22}';

const obj = JSON.parse(json);

console.log(obj.name);        // expected output: Archana

console.log(obj.age);        // expected output: 22

AI Generated Answer

AI is thinking...

13.  Write short notes on:

a.       HTML DOM

b.       Tag libraries


5 marks
Details
Official Answer

a. HTML DOM

The HTML DOM is an Object Model for HTML. It defines:

  • HTML elements as objects
  • Properties for all HTML elements
  • Methods for all HTML elements
  • Events for all HTML elements

When a web page is loaded, the browser creates a Document Object Model of the page. The HTML DOM model is constructed as a tree of Objects:

DOM HTML tree

b. Tag libraries 

In a Web application, a common design goal is to separate the display code from business logic. Java tag libraries are one solution to this problem. Tag libraries allow you to isolate business logic from the display code by creating a Tag class (which performs the business logic) and including an HTML-like tag in your JSP page. When the Web server encounters the tag within your JSP page, the Web server will call methods within the corresponding Java Tag class to produce the required HTML content.

A tag library defines a collection of custom actions. The tags can be used directly by developers in manually coding a JSP page, or automatically by Java development tools. A tag library must be portable between different JSP container implementations.

A custom tag library is made accessible to a JSP page through a taglib directive of the following general form:

<%@ taglib uri="URI" prefix="prefix" %>
AI Generated Answer

AI is thinking...

13.  What do you mean by cookies? Explain with example.

5 marks
Details
Official Answer

A cookie is a variable that is stored on the visitor's computer. Cookies let you store user information in web pages.

When a web server has sent a web page to a browser, the connection is shut down, and the server forgets everything about the user. Cookies were invented to solve the problem "how to remember information about the user".

  • When a user visits a web page, his/her name can be stored in a cookie.
  • Next time the user visits the page, the cookie "remembers" his/her name.

Cookies are saved in name-value pairs like:

    username = Ronaldo

When a browser requests a web page from a server, cookies belonging to the page are added to the request. This way the server gets the necessary data to "remember" information about users.

JavaScript Cookies

E.g.

JavaScript code to set and get a cookie:

<!DOCTYPE html>  

<html>  

<head>  

</head>  

<body>  

<input type="button" value="setCookie" onclick="setCookie()">  

<input type="button" value="getCookie" onclick="getCookie()">  

    <script>  

    function setCookie()  

    {  

        document.cookie="username=Jayanta";  

    }  

    function getCookie()  

    {  

        if(document.cookie.length!=0)  

        {  

        alert(document.cookie);  

        }  

        else  

        {  

        alert("Cookie not available");  

        }  

    }  

    </script>  

</body>  

</html>  

AI Generated Answer

AI is thinking...

Unit 5: AJAX and XML
33 Questions

2.  Create a small XML file designed to contain information about student performance on a module. Each student has a name, roll no, a subject mark and an exam mark.

10 marks
Details
Official Answer

<?xml version="1.0" encoding="utf-8" ?>

 <performance>

    <student>

        <Name>Barsha</Name>

        <Roll_Number>1</Roll_Number>

        <Subject_Mark>80</Subject_Mark>

        <Exam_Mark>30</Exam_Mark>

    </student>

    <student>

        <Name>Priyanka</Name>

        <Roll_Number>2</Roll_Number>

        <Subject_Mark>80</Subject_Mark>

        <Exam_Mark>45</Exam_Mark>

    </student>

    <student>

        <Name>Swastima</Name>

        <Roll_Number>3</Roll_Number>

        <Subject_Mark>80</Subject_Mark>

        <Exam_Mark>55</Exam_Mark>

    </student>

    <student>

        <Name>Rashmika</Name>

        <Roll_Number>4</Roll_Number>

        <Subject_Mark>80</Subject_Mark>

        <Exam_Mark>65</Exam_Mark>

    </student>

</performance>

AI Generated Answer

AI is thinking...

2.  What is XML? Discuss the structure of XML file with example. Write an XML schema to describe “address” as an element and “city, state, street and house-no” as its attributes.

10 marks
Details
Official Answer

XML (Extensible Markup Language) is a software- and hardware-independent tool for storing and transporting data. XML is a markup language that defines a set of rules for encoding documents in a format that is both human readable and machine readable. It has no predefined tags.

The major portions of an XML document include the following:

  • The XML declaration: XML document can optionally have an XML declaration. It must be be the first statement of the XML document. The XML declaration is a processing instruction of the form <?xml........?>
  • The document Type Declaration (DTD): It gives a name to the XML content, and provides a means to guarantee the document's validity either by including or specifying a link to a DTD. It is optional in XML.
  • The element data: XML elements are either a matched pair of XML tags or single XML tags that are "self-closing". For e.g. A address element begins with <address> and ends with </address>. When elements do not come in pairs, the element name is suffixed by the forward slash. XML documents must contain one root element that is the parent of all other elements.
  • The attribute data: It is additional information that can be communicated to XML processors  They are name/value pairs contained within the start element. E.g. <price currency="USD">...</price>
  • The character data or XML content: XML content can consists of any data, including binary data. It can contain any characters including any valid Unicode and International characters.

E.g. of XML

<?xml version="1.0" encoding="UTF-8"?>

<note>

  <to> Sandhya </to>

  <from> Barsha </from>

  <heading> Reminder </heading>

  <body> Don't forget me this weekend! </body>

</note>


XML schema for given elements and attributes

//Address.xml

<?xml version="1.0" encoding="utf-8" ?>

<Information xmlns:xsi="www.w3.org/2001/XMLSchema-Instance" xsi:noNameSpaceSchemaLocation="Address.xsd">

<Address City="Kathmandu" State="Bagmati" Street="Madhevsthan Road" House-No="110"></Address>

</Information>


//Address.xsd

<?xml version="1.0" encoding="utf-8"?>

<xs:schema xmlns:xsd="http://www.w3.or./2001.XMLSchema">

 <xs:element name="Information">

  <xs:complexType>

   <xs:sequence>

    <xs:element name="Address">

     <xs:complexType>

        <xs:attribute name="City" type="xsd:string" use="required">

        <xs:attribute name="State" type="xsd:string" use="required">

        <xs:attribute name="Street" type="xsd:string" use="required">

        <xs:attribute name="House-No" type="xsd:string" use="required">

     </xs:complexType>

    </xs:element>

   </xs:sequence>

  </xs:complexType>

 </xs:element>

</xs:schema>

AI Generated Answer

AI is thinking...

2. Define XML schema. Compare it with DTD. Write a schema to describe "name" as a root element and "first_name","middle_name" and "last_name" as child elements.

10 marks
Details
Official Answer

XML schema is a language which is used for expressing constraint about XML documents. It is used to define the structure of an XML document. It is like DTD but provides more control on XML structure.

Comparison between DTD and XML schema

  • XML schemas are written in XML while DTD are derived from SGML syntax.
  • XML schemas define datatypes for elements and attributes while DTD doesn't support datatypes.
  • XML schemas allow support for namespaces while DTD does not.
  • XML schemas define number and order of child elements, while DTD does not.
  • XML schemas can be manipulated on your own with XML DOM but it is not possible in case of DTD.
  • using XML schema user need not to learn a new language but working with DTD is difficult for a user.
  • XML schema provides secure data communication i.e. sender can describe the data in a way that receiver will understand, but in case of DTD data can be misunderstood by the receiver.
  • XML schemas are extensible while DTD is not extensible.

XML schema to describe given elements

//name.xml

<?xml version="1.0" encoding="UTF-8"?>

<name xsi:schemalocation="name.xsd">

    <first_name>Surya</first_name>

    <middle_name>chandra</middle_name>

    <last_name>Basnet</last_name>

</name>


// name.xsd

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="name">

  <xs:complexType>

    <xs:sequence>

      <xs:element name="first_name" type="xs:string"/>

      <xs:element name="middle_name" type="xs:string"/>

      <xs:element name="last_name" type="xs:string"/>

    </xs:sequence>

  </xs:complexType>

</xs:element>

</xs:schema>

AI Generated Answer

AI is thinking...

2.  Explain the use of XML in web development. Write internal and external DTD to describe "mail" as a root element and "to", "from", and "subject", and "message" as child elements.

10 marks
Details
Official Answer

Extensible markup Language (XML) plays a significant role in the present world of web development, it is perfectly useful for those who wish to make use of web technologies for distributing information across the web. Like HTML, XML is also being used to format a document with a web browser. It is an influential and effectual tool to process a document’s contents and therefore, creating own tags is possible with XML. It gels well with any operating system and maintains a great amount of flexibility, which is very essential for the web development scenario.

Uses:

  • XML is used to separate data from presentation
  • XML is used to store and transport data.
  • XML is used to separate data from HTML.
  • 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
  • XML can be used to create new internet languages. For e.g. XHTML, WSDL

Now,

Internal DTD for given elements

//mail.dtd

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE mail[

<!ELEMENT mail(to, from, subject, message)>

<!ELEMENT to(#PCDATA)>

<!ELEMENT from(#PCDATA)>

<!ELEMENT subject(#PCDATA)>

<!ELEMENT message(#PCDATA)>

]>

<mail>

    <to>Jayanta</to>

    <from>Sagar</from>

    <subject>webtech</subject>

    <message> Never miss the web tech class</message>

</mail>

External DTD for given elements

//mail.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE mail SYSTEM "mail.dtd">

<mail>

    <to>Jayanta</to>

    <from>Sagar</from>

    <subject>webtech</subject>

    <message> Never miss the web tech class</message>

</mail>

//mail.dtd   

<!ELEMENT mail(to, from, subject, message)>

<!ELEMENT to(#PCDATA)>

<!ELEMENT from(#PCDATA)>

<!ELEMENT subject(#PCDATA)>

<!ELEMENT message(#PCDATA)>

AI Generated Answer

AI is thinking...

2.  What is the use of XSLT? Create a XML file with elements and elements having attributes. Write the equivalent XSLT of the XML for rendering as a HTML document in a browser.

10 marks
Details
Official Answer

XSLT (Extensible Stylesheet Language Transformations) is a language for transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text or XSL Formatting Objects, which may subsequently be converted to other formats, such as PDF, Postscript and PNG. 

The original document is not changed; rather, a new document is created based on the content of an existing one. Typically, input documents are XML files, but anything from which the processor can build an XQuery and XPath Data Model can be used, such as relational database tables or geographical information system.

Creating Students.xml as:

<?xml version="1.0" encoding="UTF-8"?> 

<?xml-stylesheet type="text/xsl "href="student.xsl" ?> 

 <student> 

  <s> 

   <name> Jayanta </name> 

   <branch> CS</branch> 

   <age>20</age> 

   <city> Kathmandu </city> 

  </s> 

  <s> 

   <name> Manoj </name> 

   <branch> IT </branch> 

   <age> 20</age> 

   <city> Pokhara </city> 

  </s> 

  <s>  

   <name> Sagar</name> 

   <branch> HM </branch> 

   <age> 23</age> 

   <city> Biratnagar </city> 

  </s> 

 </student> 

Now,  equivalent XSLT of the above XML for rendering as a HTML document in a browser is given below:

// student.xsl

<?xml version="1.0" encoding="UTF-8"?> 

<xsl:stylesheet version="1.0" 

  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

<xsl:template match="/"> 

 <html> 

 <body> 

  <h1 align="center">Students' Basic Details</h1> 

   <table border="3" align="center" > 

   <tr> 

    <th>Name</th> 

    <th>Branch</th> 

    <th>Age</th> 

    <th>City</th> 

   </tr> 

    <xsl:for-each select="student/s"> 

   <tr> 

    <td><xsl:value-of select="name"/></td> 

    <td><xsl:value-of select="branch"/></td> 

    <td><xsl:value-of select="age"/></td> 

    <td><xsl:value-of select="city"/></td> 

   </tr> 

    </xsl:for-each> 

    </table> 

</body> 

</html> 

</xsl:template> 

</xsl:stylesheet> 

AI Generated Answer

AI is thinking...

3. Explain about XML and how to create HTML document with the help of XML.

10 marks
Details
Official Answer

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. 

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.

We can create HTML document from XML using XSLT.

XSLT (Extensible Stylesheet Language Transformations) is a language for transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text or XSL Formatting Objects, which may subsequently be converted to other formats, such as PDF, Postscript and PNG. 

The original document is not changed; rather, a new document is created based on the content of an existing one. Typically, input documents are XML files, but anything from which the processor can build an XQuery and XPath Data Model can be used, such as relational database tables or geographical information system.

Creating Students.xml as:

<?xml version="1.0" encoding="UTF-8"?> 

<?xml-stylesheet type="text/xsl "href="student.xsl" ?> 

 <student> 

  <s> 

   <name> Jayanta </name> 

   <branch> CS</branch> 

   <age>20</age> 

   <city> Kathmandu </city> 

  </s> 

  <s> 

   <name> Sabina </name> 

   <branch> IT </branch> 

   <age> 20</age> 

   <city> Pokhara </city> 

  </s> 

 </student> 

Now,  equivalent XSLT of the above XML for rendering as a HTML document in a browser is given below:

// student.xsl

<?xml version="1.0" encoding="UTF-8"?> 

<xsl:stylesheet version="1.0" 

  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

<xsl:template match="/"> 

 <html> 

 <body> 

  <h1 align="center">Students' Basic Details</h1> 

   <table border="3" align="center" > 

   <tr> 

    <th>Name</th> 

    <th>Branch</th> 

    <th>Age</th> 

    <th>City</th> 

   </tr> 

    <xsl:for-each select="student/s"> 

   <tr> 

    <td><xsl:value-of select="name"/></td> 

    <td><xsl:value-of select="branch"/></td> 

    <td><xsl:value-of select="age"/></td> 

    <td><xsl:value-of select="city"/></td> 

   </tr> 

    </xsl:for-each> 

    </table> 

</body> 

</html> 

</xsl:template> 

</xsl:stylesheet> 

AI Generated Answer

AI is thinking...

3.  What are elements and attributes of XML document? What is XML schema? Differentiate XML schema with DTD. Write a simple example of DTD.

10 marks
Details
Official Answer

XML elements and attributes

XML elements can be defined as building blocks of an XML. Elements can behave as containers to hold text, elements, attributes, media objects or all of these. 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.

XML attributes are part of XML elements. An element can have multiple unique attributes. Attribute gives more information about XML elements. To be more precise, they define properties of elements. An XML attribute is always a name-value pair.

Sytnatx:

<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. An empty element (element with no content) has following syntax −

            <name attribute1 attribute2.../>

  • 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"

E.g.

<?xml version = "1.0"?>

<contact-info>

   <address category = "residence">    //category is attribute

      <name> Alisha </name>

      <phone>01-1234567</phone>

   </address>

</contact-info>


Difference between XML schema and DTD

  • XML schemas are written in XML while DTD are derived from SGML syntax.
  • XML schemas define datatypes for elements and attributes while DTD doesn't support datatypes.
  • XML schemas allow support for namespaces while DTD does not.
  • XML schemas define number and order of child elements, while DTD does not.
  • XML schemas can be manipulated on your own with XML DOM but it is not possible in case of DTD.
  • using XML schema user need not to learn a new language but working with DTD is difficult for a user.
  • XML schema provides secure data communication i.e. sender can describe the data in a way that receiver will understand, but in case of DTD data can be misunderstood by the receiver.
  • XML schemas are extensible while DTD is not extensible.


Example of DTD

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE mail[

<!ELEMENT mail(to, from, subject, message)>

<!ELEMENT to(#PCDATA)>

<!ELEMENT from(#PCDATA)>

<!ELEMENT subject(#PCDATA)>

<!ELEMENT message(#PCDATA)>

]>

<mail>

    <to> Jayanta </to>

    <from> Arjun </from>

    <subject> webtech </subject>

    <message> Never miss the web tech class </message>

</mail>

AI Generated Answer

AI is thinking...

3.  Discuss the benefits of using XML. Differentiate XML schema with DTD. Write an XML DTD to describe “person” as an element and “Name, address, phone-no, and Age” as its attributes.

10 marks
Details
Official Answer

XML (Extensible Markup Language) is  a markup language that defines a set of rules for encoding documents in a format that is both human readable and machine readable. XML is designed to store and transport data.

Benefits of using XML

  • Simplicity: Information coded in XML is easy to read and understand, plus it can be processed easily by computers.
  • Openness: XML is a W3C standard, endorsed by software industry market leaders.
  • Extensibility: There is no fixed set of tags. New tags can be created as they are needed.
  • Self-description: XML documents can be stored without [schemas] because they contain meta data; any XML tag can possess an unlimited number of attributes such as author or version.
  • Contains machine-readable context information: Tags, attributes and element structure provide context information ... opening up new possibilities for highly efficient search engines, intelligent data mining, agents, etc.
  • Separates content from presentation: XML tags describe meaning not presentation. The look and feel of an XML document can be controlled by XSL stylesheets, allowing the look of a document (or of a complete Web site) to be changed without touching the content of the document. Multiple views or presentations of the same content are easily rendered.
  • Supports multilingual documents and Unicode: This is important for the internationalization of applications.
  • Facilitates the comparison and aggregation of data: The tree structure of XML documents allows documents to be compared and aggregated efficiently element by element.
  • Can embed multiple data types: XML documents can contain any possible data type — from multimedia data (image, sound, video) to active components (Java applets, ActiveX).
  • Can embed existing data: Mapping existing data structures like file systems or relational databases to XML is simple....
  • Provides a “one-server view” for distributed data: XML documents can consist of nested elements that are distributed over multiple remote servers. XML is currently the most sophisticated format for distributed data — the World Wide Web can be seen as one huge XML database.

Difference between XML schema and DTD

  • XML schemas are written in XML while DTD are derived from SGML syntax.
  • XML schemas define datatypes for elements and attributes while DTD doesn't support datatypes.
  • XML schemas allow support for namespaces while DTD does not.
  • XML schemas define number and order of child elements, while DTD does not.
  • XML schemas can be manipulated on your own with XML DOM but it is not possible in case of DTD.
  • using XML schema user need not to learn a new language but working with DTD is difficult for a user.
  • XML schema provides secure data communication i.e. sender can describe the data in a way that receiver will understand, but in case of DTD data can be misunderstood by the receiver.
  • XML schemas are extensible while DTD is not extensible.

XML DTD to describe given element and attributes

<?xml version="1.0" encoding="utf-8" ?>

<!DOCTYPE person

[

<!ELEMENT person EMPTY>

<!ATTLIST person Name CDATA #REQUIRED >

<!ATTLIST person address CDATA #REQUIRED >

<!ATTLIST person phone-no CDATA #REQUIRED >

<!ATTLIST person Age CDATA #REQUIRED >

]>

<person Name="Jayanta" address="Ramechhap" phone-no="9843000000" Age="20"></person>

AI Generated Answer

AI is thinking...

7.  Compare XML schema with DTD.

5 marks
Details
Official Answer

Comparison between XML schema and DTD

  • XML schemas are written in XML while DTD are derived from SGML syntax.
  • XML schemas define datatypes for elements and attributes while DTD doesn't support datatypes.
  • XML schemas allow support for namespaces while DTD does not.
  • XML schemas define number and order of child elements, while DTD does not.
  • XML schemas can be manipulated on your own with XML DOM but it is not possible in case of DTD.
  • using XML schema user need not to learn a new language but working with DTD is difficult for a user.
  • XML schema provides secure data communication i.e. sender can describe the data in a way that receiver will understand, but in case of DTD data can be misunderstood by the receiver.
  • XML schemas are extensible while DTD is not extensible.
AI Generated Answer

AI is thinking...

7.  What are the advantages of using XML? Explain the rules for writing XML.

5 marks
Details
Official Answer

Advantages of using XML

  • Simplicity: Information coded in XML is easy to read and understand, plus it can be processed easily by computers.
  • Openness: XML is a W3C standard, endorsed by software industry market leaders.
  • Extensibility: There is no fixed set of tags. New tags can be created as they are needed.
  • Self-description: XML documents can be stored without [schemas] because they contain meta data; any XML tag can possess an unlimited number of attributes such as author or version.
  • Contains machine-readable context information: Tags, attributes and element structure provide context information ... opening up new possibilities for highly efficient search engines, intelligent data mining, agents, etc.
  • Separates content from presentation: XML tags describe meaning not presentation. The look and feel of an XML document can be controlled by XSL stylesheets, allowing the look of a document (or of a complete Web site) to be changed without touching the content of the document. Multiple views or presentations of the same content are easily rendered.
  • Supports multilingual documents and Unicode: This is important for the internationalization of applications.
  • Facilitates the comparison and aggregation of data: The tree structure of XML documents allows documents to be compared and aggregated efficiently element by element.
  • Can embed multiple data types: XML documents can contain any possible data type — from multimedia data (image, sound, video) to active components (Java applets, ActiveX).
  • Can embed existing data: Mapping existing data structures like file systems or relational databases to XML is simple....
  • Provides a “one-server view” for distributed data: XML documents can consist of nested elements that are distributed over multiple remote servers. XML is currently the most sophisticated format for distributed data — the World Wide Web can be seen as one huge XML database.

Rules for writing XML

1. All XML Elements Must Have a Closing Tag. In XML, it is illegal to omit the closing tag. All elements must have a closing tag:

    E.g. Correct: <p>This is a paragraph.</p>

           Incorrect: <p>This is a paragraph.

2. XML tags are case sensitive. The tag <Letter> is different from the tag <letter>. Opening and closing tags must be written with the same case:

   E.g. Incorrect: <Message>This is incorrect</message>   

       Correct: <message>This is correct</message>    

3. In XML, all elements must be properly nested within each other:

    E.g. Incorrect: <b><i>This text is bold and italic</b></i>

        Correct: <b><i>This text is bold and italic</i></b>

4. XML Documents Must Have a Root Element. XML documents must contain one element that is the parent of all other elements. This element is called the root element.

<root>

    <child>

        <subchild>.....</subchild>

    </child>

</root>

5. XML Attribute Values Must be Quoted.

<note date="06/01/2012">

    <to>Tulsi</to>

    <from>Giri</from>

</note>

6. Comments in XML.

The syntax for writing comments in XML is similar to that of HTML.

    <!-- This is a comment -->

7. White-space is preserved in XML. 

8. Avoid HTML tags.

AI Generated Answer

AI is thinking...

7.  Explain the XML syntax and structure rules.

5 marks
Details
Official Answer

The syntax rules of XML are very simple and logical. The rules are easy to learn, and easy to use.

XML syntax and structure rules are:

1. All XML Elements Must Have a Closing Tag. In XML, it is illegal to omit the closing tag. All elements must have a closing tag:

    E.g. Correct: <p>This is a paragraph.</p>

           Incorrect: <p>This is a paragraph.

2. XML tags are case sensitive. The tag <Letter> is different from the tag <letter>. Opening and closing tags must be written with the same case:

   E.g. Incorrect: <Message>This is incorrect</message>   

       Correct: <message>This is correct</message>    

3. In XML, all elements must be properly nested within each other:

    E.g. Incorrect: <b><i>This text is bold and italic</b></i>

        Correct: <b><i>This text is bold and italic</i></b>

4. XML Documents Must Have a Root Element. XML documents must contain one element that is the parent of all other elements. This element is called the root element.

<root>

    <child>

        <subchild>.....</subchild>

    </child>

</root>

5. XML Attribute Values Must be Quoted.

<note date="06/01/2012">

    <to>Tulsi</to>

    <from>Giri</from>

</note>

6. Comments in XML.

The syntax for writing comments in XML is similar to that of HTML.

    <!-- This is a comment -->

7. White-space is preserved in XML. 

8. Avoid HTML tags.

AI Generated Answer

AI is thinking...

7.  How to transform XML documents to others forms? Explain.

5 marks
Details
Official Answer

XML document can be transformed into into other forms using XSLT.

XSLT (Extensible Stylesheet Language Transformations) is a language for transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text or XSL Formatting Objects, which may subsequently be converted to other formats, such as PDF, Postscript and PNG. 

The original document is not changed; rather, a new document is created based on the content of an existing one. Typically, input documents are XML files, but anything from which the processor can build an XQuery and XPath Data Model can be used, such as relational database tables or geographical information system.

E.g.

Creating Students.xml as:

<?xml version="1.0" encoding="UTF-8"?> 

<?xml-stylesheet type="text/xsl "href="student.xsl" ?> 

 <student> 

  <s> 

   <name> Jayanta </name> 

   <branch> CS</branch> 

   <age>20</age> 

   <city> Kathmandu </city> 

  </s> 

  <s> 

   <name> Manoj </name> 

   <branch> IT </branch> 

   <age> 20</age> 

   <city> Pokhara </city> 

  </s> 

 </student> 

Now,  equivalent XSLT of the above XML for rendering as a HTML document in a browser is given below:

// student.xsl

<?xml version="1.0" encoding="UTF-8"?> 

<xsl:stylesheet version="1.0" 

  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

<xsl:template match="/"> 

 <html> 

 <body> 

  <h1 align="center">Students' Basic Details</h1> 

   <table border="3" align="center" > 

   <tr> 

    <th>Name</th> 

    <th>Branch</th> 

    <th>Age</th> 

    <th>City</th> 

   </tr> 

    <xsl:for-each select="student/s"> 

   <tr> 

    <td><xsl:value-of select="name"/></td> 

    <td><xsl:value-of select="branch"/></td> 

    <td><xsl:value-of select="age"/></td> 

    <td><xsl:value-of select="city"/></td> 

   </tr> 

    </xsl:for-each> 

    </table> 

</body> 

</html> 

</xsl:template> 

</xsl:stylesheet> 

AI Generated Answer

AI is thinking...

8.  How to represent data types in XML schema? Explain.

5 marks
Details
Official Answer

One of the greatest strength of XML Schemas is the support for data types. Using XML schema it is easier to describe allowable document content; it is easier to validate the correctness of data; it is easier to convert data between different data types.

Built in data types supported by XML schema:

XML Schema has a lot of built-in data types. The most common types are:

xs:string

xs:decimal

xs:integer

xs:boolean

xs:date

xs:time

XML schema defines in the namespace http://www.w3.org/2001/XMLschema that contains built in data types. There are two classes of XML schema data types:

Complex type is a data type is represented using markup.

Simple type is a data type whose values are represented in XML doc by character data. XML markup such as <types> is known as XML schema that conforms to W3C defined XML schema vocabulary which defines all or part of the vocabulary for another XML document. The <schema> is the root element for any XML schema document. The child elements of schema define the data types.

Example for writing a simple XML Schema:

<?xml version=”1.0”?>

<xs:schema xmlns:xs=” http://www.w3.org/2001/XMLSchma”>

<xs:element name=”student” >

 <xs:complexType>

  <xs:sequence>

   <xs:element name=”name” value=”xs:string” />

   <xs:element name=”regno” value=”xs:string” /> 

   <xs:element name=”dept” value=”xs:string” /> 

  </xs:sequence>

 </xs:complexType>

</xs:element>

</xs:schema>

AI Generated Answer

AI is thinking...

8.  Mention the application of XSL.

5 marks
Details
Official Answer

Separating format from content is all well and good, but sooner or later you need to format information for presentation. XML by itself is not acceptable for display to the average user. The technology for formatting XML presentation is eXtensible Stylesheet Language (XSL). Unlike traditional style sheets, which provide only formatting commands, XSL is a powerful mechanism for both transforming and formatting XML documents.

XSL is an XML markup language itself and as such, can

  • Format content for online display or for paper-based delivery

  • Add constant text or graphics (such as the icons in the "warning" example)

  • Filter content

  • Sort or reorder text

AI Generated Answer

AI is thinking...

8.  What are the advantages of XML over the HTML?

5 marks
Details
Official Answer

Advantages of XML over HTML are:

  • XML encodes data in tightly-validated tree structures. Data is easy to locate since its context is well defined by tags and rules of structure.

  • HTML attempts to control the appearance and presentation of data, while XML does not. XML defines data separately from its presentation. This makes XML data easier to locate and manipulate.

  • XML is a standard data format that permits applications to exchange information across platforms and operating systems. HTML is markup used to display information in a web browser.

  • XML is open and extensible. XML authors can create their own tags. HTML is limited by a fixed vocabulary that browser developers have agreed to support. In fact, XML has no predefined tags of its own. New XML tags are defined as needed —to define any type of data using syntactical rules that that permit browsers and XML Parsers to interpret proprietary tags on the fly. 

  • Since XML is plain text, it is easily transmitted between computers and through firewalls. XML is more secure than binary files, since text files cannot be executed directly. Binary files, on the other hand, can contain malicious computer programs.

  • XML is universally compatible. The XML file format is not tied to any particular program, operating system, database, or network. XML can be used by non-web applications to store data.

  • XML files can be transformed into other types of documents. Transformation is controlled using XSL style sheets.

AI Generated Answer

AI is thinking...

9.  Why do we need XSLT? Explain XSL <xls:for-each> Element.

5 marks
Details
Official Answer

XSLT (Extensible Stylesheet Language Transformations) provides the ability to transform XML data from one format to another automatically.  It is the recommended style sheet language for XML.

XSLT is far more sophisticated than CSS. With XSLT we can add/remove elements and attributes to or from the output file. We can also rearrange and sort elements, perform tests and make decisions about which elements to hide and display, and a lot more.

XSLT uses XPath to find information in an XML document.

<xls:for-each> Element

  • The <xsl:for-each> element allows you to do looping in XSLT.
  • The XSL <xsl:for-each> element can be used to select every XML element of a specified node-set.
  • The XSLT <xsl:for-each> element is used to apply a template repeatedly for each node.

syntax:

<xsl:for-each

   select = Expression >  

</xsl:for-each>

E.g.

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">

  <html>

  <body>

  <h2>My CD Collection</h2>

  <table border="1">

    <tr bgcolor="#9acd32">

      <th>Title</th>

      <th>Artist</th>

    </tr>

    <xsl:for-each select="catalog/cd">

    <tr>

      <td><xsl:value-of select="title"/></td>

      <td><xsl:value-of select="artist"/></td>

    </tr>

    </xsl:for-each>

  </table>

  </body>

  </html>

</xsl:template>

AI Generated Answer

AI is thinking...

10.  Discuss the rules of writing XML document.

5 marks
Details
Official Answer

The syntax rules of XML are very simple and logical. The rules are easy to learn, and easy to use.

Rules for writing XML document:

1. All XML Elements Must Have a Closing Tag. In XML, it is illegal to omit the closing tag. All elements must have a closing tag:

    E.g. Correct: <p>This is a paragraph.</p>

           Incorrect: <p>This is a paragraph.

2. XML tags are case sensitive. The tag <Letter> is different from the tag <letter>. Opening and closing tags must be written with the same case:

   E.g. Incorrect: <Message>This is incorrect</message>   

       Correct: <message>This is correct</message>    

3. In XML, all elements must be properly nested within each other:

    E.g. Incorrect: <b><i>This text is bold and italic</b></i>

        Correct: <b><i>This text is bold and italic</i></b>

4. XML Documents Must Have a Root Element. XML documents must contain one element that is the parent of all other elements. This element is called the root element.

<root>

    <child>

        <subchild>.....</subchild>

    </child>

</root>

5. XML Attribute Values Must be Quoted.

<note date="06/01/2012">

    <to>Tulsi</to>

    <from>Giri</from>

</note>

6. Comments in XML.

The syntax for writing comments in XML is similar to that of HTML.

    <!-- This is a comment -->

7. White-space is preserved in XML. 

8. Avoid HTML tags.

AI Generated Answer

AI is thinking...

9.  What are the benefits and drawbacks of using XML name space?

5 marks
Details
Official Answer

XML Namespace is a mechanism to avoid name conflicts by differentiating elements or attributes within an XML document that may have identical names, but different definitions.

Consider two XML fragment:

//1.xml

<table>

  <tr>

    <td>Apples</td>

    <td>Bananas</td>

  </tr>

</table>

//2.xml

<table>

  <name>African Coffee Table</name>

  <width>80</width>

  <length>120</length>

</table>

If these XML fragments were added together, there would be a name conflict. Both contain a <table> element, but the elements have different content and meaning.

Name conflicts in XML can easily be avoided using a name prefix.

E.g.

<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>

In this example, there will be no conflict because the two <table> elements have different names.

Advantages
  • It helps us avoid real name clashes with other XML vocabularies.
  • Moreover, namespaces may be used, if XML documents will be distributed to others, when name collisions may really become an issue.
Disadvantages
  • Namespaces, increases the size of XML documents.
  • With namespaces, we need to be extra careful while writing applications (all our programming expressions, querying & creating the XML nodes must be namespace aware). This namespace-awareness overhead (effort to create, and maintain) should be incurred, only if an application requires it (i.e, if management of name collisions is really needed).
AI Generated Answer

AI is thinking...

9.  How is XML defined? What are the benefits of using XML namespace?

5 marks
Details
Official Answer

XML (Extensible Markup Language) is  a markup language that defines a set of rules for encoding documents in a format that is both human readable and machine readable. XML is designed to store and transport data.


XML Namespace is a mechanism to avoid name conflicts by differentiating elements or attributes within an XML document that may have identical names, but different definitions.

Consider two XML fragment:

//1.xml

<table>

  <tr>

    <td>Apples</td>

    <td>Bananas</td>

  </tr>

</table>

//2.xml

<table>

  <name>African Coffee Table</name>

  <width>80</width>

  <length>120</length>

</table>

If these XML fragments were added together, there would be a name conflict. Both contain a <table> element, but the elements have different content and meaning.

Name conflicts in XML can easily be avoided using a name prefix.

E.g.

<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>

In this example, there will be no conflict because the two <table> elements have different names.

Benifits of XML Namespace
  • It helps us avoid real name clashes with other XML vocabularies.
  • Moreover, namespaces may be used, if XML documents will be distributed to others, when name collisions may really become an issue.
AI Generated Answer

AI is thinking...

9.  Why do we need XSLT? Explain XSL<xsl:if> Element.

5 marks
Details
Official Answer

XSLT (Extensible Stylesheet Language Transformations) provides the ability to transform XML data from one format to another automatically.  It is the recommended style sheet language for XML.

XSLT is far more sophisticated than CSS. With XSLT we can add/remove elements and attributes to or from the output file. We can also rearrange and sort elements, perform tests and make decisions about which elements to hide and display, and a lot more.

XSLT uses XPath to find information in an XML document.

<xsl:if> Element

The XSLT <xsl:if> element is used to specify a conditional test against the content of the XML file.

Syntax:

<xsl:if test="expression">  

  ...some output if the expression is true...  

</xsl:if>   

E.g.

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">

  <html>

  <body>

  <h2>My CD Collection</h2>

  <table border="1">

    <tr bgcolor="#9acd32">

      <th>Title</th>

      <th>Artist</th>

      <th>Price</th>

    </tr>

    <xsl:for-each select="catalog/cd">

      <xsl:if test="price &gt; 10">

        <tr>

          <td><xsl:value-of select="title"/></td>

          <td><xsl:value-of select="artist"/></td>

          <td><xsl:value-of select="price"/></td>

        </tr>

      </xsl:if>

    </xsl:for-each>

  </table>

  </body>

  </html>

</xsl:template>

</xsl:stylesheet>

The code above will only output the title and artist elements of the CDs that has a price that is higher than 10.

AI Generated Answer

AI is thinking...

9. What is XML namespace? How it is used in XML files?

5 marks
Details
Official Answer

XML Namespace is a mechanism to avoid name conflicts by differentiating elements or attributes within an XML document that may have identical names, but different definitions.

Consider two XML fragment:

//1.xml

<table>

  <tr>

    <td>Apples</td>

    <td>Bananas</td>

  </tr>

</table>

//2.xml

<table>

  <name>African Coffee Table</name>

  <width>80</width>

  <length>120</length>

</table>

If these XML fragments were added together, there would be a name conflict. Both contain a <table> element, but the elements have different content and meaning.

XML namespace is used in XML files as:

1) Using a prefix

Name conflicts in XML can easily be avoided using a name prefix.

E.g.

<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>

In this example, there will be no conflict because the two <table> elements have different names.

2) Using xmlns Attribute

When using prefixes in XML, a namespace for the prefix must be defined. The namespace can be defined by an xmlns attribute in the start tag of an element.

The namespace declaration has the following syntax. xmlns:prefix="URI".

E.g.
<root>
<h:table xmlns:h="http://www.w3.org/TR/html4/">
  <h:tr>
    <h:td>Apples</h:td>
    <h:td>Bananas</h:td>
  </h:tr>
</h:table>

<f:table xmlns:f="https://www.w3schools.com/furniture">
  <f:name>African Coffee Table</f:name>
  <f:width>80</f:width>
  <f:length>120</f:length>
</f:table>
</root>

The purpose of using an URI is to give the namespace a unique name.
AI Generated Answer

AI is thinking...

10.  What are the various contents of an element in a DTD? Explain.

5 marks
Details
Official Answer

XML elements can be defined as building blocks of an XML document. Elements can behave as a container to hold text, elements, attributes, media objects or mix of all. A DTD element is declared with an ELEMENT declaration. 

All DTD element declarations have this general form −

<!ELEMENT elementname (content)>

  • ELEMENT declaration is used to indicate the parser that you are about to define an element.
  • elementname is the element name (also called the generic identifier) that you are defining.
  • content defines what content (if any) can go within the element.

Content of elements declaration in a DTD can be categorized as below :

1. Empty Content

This is a special case of element declaration. This element declaration does not contain any content. These are declared with the keyword EMPTY.

Syntax:

<!ELEMENT elementname EMPTY >

2. Element Content

In element declaration with element content, the content would be allowable elements within parentheses. We can also include more than one element.

Syntax:

<!ELEMENT elementname (child1, child2...)>

3. Mixed Element Content

This is the combination of (#PCDATA) and children elements. PCDATA stands for parsed character data, that is, text that is not markup. Within mixed content models, text can appear by itself or it can be interspersed between elements. The rules for mixed content models are similar to the element content as discussed in the previous section.

Syntax:

<!ELEMENT elementname (#PCDATA|child1|child2)*>

4. ANY Element Content

You can declare an element using the ANY keyword in the content. It is most often referred to as mixed category element. ANY is useful when you have yet to decide the allowable contents of the element.

Syntax:

<!ELEMENT elementname ANY>

AI Generated Answer

AI is thinking...

10.  Why is it important to specify a DTD for an XML document? Explain.

5 marks
Details
Official Answer

DTD stands for Document Type Definition. 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.

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 DTD can be declared inline inside an XML document, or as an external reference.

It is important to specify the a DTD for an XML document because:

  • It defines the different piece of data planning to model, along with their relationship.
  • With DTD, each of your XML files can carry a description of its own format with it.
  • With a DTD, independent groups of people can agree to use a common DTD for interchanging data.
  • Your application can use a standard DTD to verify that the data you receive from the outside world is valid.
  • You can also use a DTD to verify your own data.

Example of DTD:

<?xml version="1.0"?>  

<!DOCTYPE student [

<!ELEMENT student(firstname,lastname)>  

<!ELEMENT firstname (#PCDATA)>  

<!ELEMENT lastname (#PCDATA)>  

]>

<student>  

  <firstname>Jayanta</firstname>  

  <lastname>Poudel</lastname>  

</student>   

AI Generated Answer

AI is thinking...

10.  What is the syntax of declaring an attributes in a DTD?

5 marks
Details
Official Answer

 DTD defines the legal building blocks of an XML document. It is used to define document structure with a list of legal elements and attributes.

An attribute declaration in DTD has the following syntax:

<!ATTLIST element-name attribute-name attribute-type attribute-value>

  • element-name specifies the name of the element to which the attribute applies.
  • attribute-name specifies the name of the attribute which is included with the element-name.

The attribute-type can be one of the following:

The attribute-value can be one of the following:



E.g.

DTD example:

<!ATTLIST employee id CDATA #REQUIRED> 

XML example:

<employee id="001" />

AI Generated Answer

AI is thinking...

10.  Consider a XML file containing element name city <city> </city>. Now write its equivalent XSD to limit the content of city to a set of acceptable values from "PKR", "KTM", "NPJ".

5 marks
Details
Official Answer

<?xml version="1.0" encoding="UTF-8" ?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="city">

<xs:simpleType>

  <xs:restriction base="xs:string">

    <xs:enumeration value="PKR"/>

    <xs:enumeration value="KTM"/>

    <xs:enumeration value="NPJ"/>

  </xs:restriction>

</xs:simpleType>

</xs:element>

</xs:schema>

AI Generated Answer

AI is thinking...

10.  Discuss the private external declaration of DTD with example.

5 marks
Details
Official Answer

Private external DTDs are identified by the keyword SYSTEM, and are intended for use by a single author or group of authors.

<!DOCTYPE root_element SYSTEM "DTD_location">

where,

    DTD_location: relative or absolute URL

E.g.

<?xml version="1.0"?>

<!DOCTYPE note SYSTEM "note.dtd">

<note>

<to>Tulsi</to>

<from>Girii</from>

<heading>Reminder</heading>

<body>Don't forget me this weekend!</body>

</note>

And this is the file "note.dtd" which contains the DTD:

<!ELEMENT note (to,from,heading,body)>

<!ELEMENT to (#PCDATA)>

<!ELEMENT from (#PCDATA)>

<!ELEMENT heading (#PCDATA)>

<!ELEMENT body (#PCDATA)>

AI Generated Answer

AI is thinking...

10.  Discuss public external declaration of DTD with example.

5 marks
Details
Official Answer

In external DTD elements are declared outside the XML file.  

Public external DTDs are identified by the keyword PUBLIC and are intended for broad use. The "DTD_location" is used to find the public DTD if it cannot be located by the "DTD_name". Its syntax is:

<!DOCTYPE root_element PUBLIC "DTD_name" "DTD_location">.

where:

DTD_location: relative or absolute URL

DTD_name: follows the syntax:

    "prefix//owner_of_the_DTD//description_of_the_DTD//ISO 639_language_identifier".

If any elements, attributes, or entities are used in the XML document that are referenced or defined in an external DTD, standalone="no" must be included in the XML declarationvalidity constraint.

For example,

<?xml version="1.0" standalone="no" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
  "http://www.w3.org/TR/REC-html40/loose.dtd">
AI Generated Answer

AI is thinking...

11.  What are the components of an XML file? Explain.

5 marks
Details
Official Answer

Components of an XML file are:

1. Processing Instructions:  

An XML Documents usually begins with the XML declaration statement called the Processing Instructions .This statement provides information on how the XML file should be processed.
e.g. <?xml version =”1.0” encoding=”UTF-8”?> 
The Processing Instruction statement uses the encoding property to specify the encoding scheme used to create the XML file

2. Tags:
Tags are used to specify a name for a given piece of information. It is a means of identifying data. Data is marked up using tags.
3. Elements:
Elements are the basic units used to identify and describe the data in XML. They are the building blocks of an XML document. Elements are represented using tags.

4. Content:

Content refers to the information represented by the elements of an XML document. Consider the following example:  
 <name>Jayanta</name >

Here Jayanta is content

5. Attributes:
Attributes provide additional information about the elements for which they are declared. An attribute consists of a name-value pair. Consider the following example:
<Student_name S_ID = “101”> Jayanta </ Student_name >
6. Entities:
An entity is a name that is associated with a block of data, such as chunk of text or a reference to an external file that contains textual or binary information. It is a set of information that can be specifying a single name.
7. Comments:
Comments are statements used to explain the XML code. They are used to provide documentation information about the XML file or the application to which the file belongs. The parser ignores comments entries during code execution.

AI Generated Answer

AI is thinking...

11.  How attributes and elements are defined in a DTD? Illustrate with an example.

5 marks
Details
Official Answer

DTD stands for Document Type Definition. 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. 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.

Elements in DTD

In a DTD, elements are declared with an ELEMENT declaration. In DTD, XML elements are declared with the following syntax:

<!ELEMENT element-name category>
or
<!ELEMENT element-name (element-content)>

E.g.

<?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>Don't forget me this weekend</body>
</note>

Attributes in DTD

In a DTD, attributes are declared with an ATTLIST declaration. An attribute declaration has the following syntax:

<!ATTLIST element-name attribute-name attribute-type attribute-value>

E.g.

DTD example:

<!ATTLIST employee id CDATA #REQUIRED

XML example:

<employee id="001" />

AI Generated Answer

AI is thinking...

8. What is XML? Create an XML file containing records of employee having elements of simple and complex types.[1+4]

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

13.  Write short notes on:

        a) XML Namespace

        b) HTML DOM

5 marks
Details
Official Answer

a. XML Namespace

XML Namespace is a mechanism to avoid name conflicts by differentiating elements or attributes within an XML document that may have identical names, but different definitions.

Consider two XML fragment:

//1.xml

<table>

  <tr>

    <td>Apples</td>

    <td>Bananas</td>

  </tr>

</table>

//2.xml

<table>

  <name>African Coffee Table</name>

  <width>80</width>

  <length>120</length>

</table>

If these XML fragments were added together, there would be a name conflict. Both contain a <table> element, but the elements have different content and meaning.

Name conflicts in XML can easily be avoided using a name prefix.

E.g.

<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>

In this example, there will be no conflict because the two <table> elements have different names.

b. HTML DOM

The HTML DOM is an Object Model for HTML. It defines:

  • HTML elements as objects
  • Properties for all HTML elements
  • Methods for all HTML elements
  • Events for all HTML elements

When a web page is loaded, the browser creates a Document Object Model of the page. The HTML DOM model is constructed as a tree of Objects:

DOM HTML tree

AI Generated Answer

AI is thinking...

13.  Write short notes on:

        a) POP

        b) XPath

5 marks
Details
Official Answer

a) POP

POP (Post Office Protocol) is also called as POP3 protocol. This is a protocol used by a mail server in conjunction with SMTP to receive and holds mails for hosts.

POP3 mail server receives e-mails and filters them into the appropriate user folders. When a user connects to the mail server to retrieve his mail, the messages are downloaded from mail server to the user's hard disk.

b) XPath

XPath is an official recommendation of the World Wide Web Consortium (W3C). It defines a language to find information in an XML file. It is used to traverse elements and attributes of an XML document. XPath provides various types of expressions which can be used to enquire relevant information from the XML document.

  • Structure Definitions − XPath defines the parts of an XML document like element, attribute, text, namespace, processing-instruction, comment, and document nodes
  • Path Expressions − XPath provides powerful path expressions select nodes or list of nodes in XML documents.
  • Standard Functions − XPath provides a rich library of standard functions for manipulation of string values, numeric values, date and time comparison, node and QName manipulation, sequence manipulation, Boolean values etc.
  • Major part of XSLT − XPath is one of the major elements in XSLT standard and is must have knowledge in order to work with XSLT documents.
  • W3C recommendation − XPath is an official recommendation of World Wide Web Consortium (W3C).
AI Generated Answer

AI is thinking...

9. How XSD of a XML file is created? Illustrate with an example.[2+3]

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

Unit 6: Server Side Scripting using PHP
28 Questions

1.  Develop a simple website that stores its contents in a database and displays those contents from the database. Assume at least five different contents.

10 marks
Details
Official Answer

//index.html

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Form Registration</title>

</head>

<body>

    <h2>Client Side Form Validation</h2>

    <form method="POST" action="./formSubmit.php">

        <div>

            <label for="name">Please enter your name: </label>

            <input type="text" name="name" id="name">

        </div>

        <div>

            <label for="address">Please enter your address: </label>

            <input type="text" name="address" id="address">

        </div>

        <div>

            <label for="phoneNumber">Please enter your PhoneNumber: </label>

            <input type="text" name="phoneNumber" id="PhoneNumber">

        </div>

        <div>

            <label for="department">Please enter your Department: </label>

            <input type="text" name="department" id="department">

        </div>

        <div>

            <label for="salary">Please enter your Salary: </label>

            <input type="text" name="salary" id="salary">

        </div>

        <div>

            <input type="submit" name="signup" value="Signup">

        </div>

    </form>

</body>

</html>


//formSubmit.php

<?php

$servername = "localhost";

$username = "root";

$password = "";

$dbname = "webtech";

$tablename = "users";


if($_SERVER["REQUEST_METHOD"] == "POST"){

$name = $_POST['name'];

$address = $_POST['address'];

        $phoneNumber = $_POST['phoneNumber'];

$department = $_POST['department'];

$salary = $_POST['salary'];

    

//connect to database

$conn = mysqli_connect($servername, $username, $password) or die(mysql_error()); //Connect to server

mysqli_select_db($conn, $dbname) or die("Cannot connect to database"); //Connect to database

    

    // Insert the values into database

    mysqli_query($conn, "INSERT INTO ".$tablename."(name, address, phoneNumber, department, salary) VALUES ('$name','$address', '$phoneNumber', '$department', '$salary')");    

Print '<script>alert("Congrats! Your Submission is Successfully Registered!");</script>'; 

Print '<script>window.location.assign("display.php");</script>'; 

}

?>


//display.php

<?php

    $db = "webtech";

    $conn = mysqli_connect("localhost", "root","") or die(mysql_error());

    mysqli_select_db($conn, $db) or die("Cannot connect to database");

    $query = mysqli_query($conn, "Select * from  users"); 

?>

<html>

<head>

    <title>Displaying Data</title>

</head>

<body>

<table border="1">

<tr>

<th>Name</th>

<th>Address</th>

<th>Phone Number</th>

<th>Department</th>

<th>Salary</th>

</tr>

<?php 

     while($row = mysqli_fetch_array($query)) 

{

?>   

<tr>

<th><?php echo $row['name']; ?></th>

<th><?php echo $row['address']; ?></th>

<th><?php echo $row['phoneNumber']; ?></th>

<th><?php echo $row['department']; ?></th>

<th><?php echo $row['salary']; ?></th>

</tr>

<?php } ?>

</table>

<a href="index.html">Go back to Register New Users</a>

</body>

</html>

AI Generated Answer

AI is thinking...

1.  Develop a website that checks validity of a user during the log-in process. Assume that the login data (username and password) are already stored in a database. Use client-side script to validate the user input during login process.

5 marks
Details
Official Answer

//index.html

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Login Form</title>

</head>

<body>

    <h2>Client Side Form Validation</h2>

    <form name="loginForm" onsubmit="return validateForm();" method="POST" action="./formSubmit.php">

        <div>

            <label for="username">Please enter your username: </label>

            <input type="text" name="username" id="username">

        </div>

        <div>

            <label for="password">Please enter your password: </label>

            <input type="password" name="password" id="password">

        </div>

        <div>

            <input type="submit" name="login" value="login">

        </div>

    </form>

    <script>

        function validateForm() {

            if (document.loginForm.username.value == "") {

                alert("Please provide your usernamename!");

                document.loginForm.username.focus();

                return false;

            }

            else if (document.loginForm.password.value == "") {

                alert("Please provide your password!");

                document.loginForm.password.focus();

                return false;

            }

          else if (document.loginForm.password.value.length < 8) {

                alert('Password must be at least 8 digit long');

                document.loginForm.password.focus();

                return false;

            }

            return true;

        }

    </script>

</body>

</html>


//formSubmit.php

<?php

$servername = "localhost";

$username = "root";

$password = "";

$dbname = "webtech";

$tablename = "users";

if($_SERVER["REQUEST_METHOD"] == "POST"){

$username = $_POST['username'];

$password = $_POST['password'];


//connect to database

$conn = mysqli_connect($servername, $username, $password) or die(mysql_error()); //Connect to server

mysqli_select_db($conn, $dbname) or die("Cannot connect to database"); //Connect to database


        // Insert the values into database

mysqli_query($conn, "INSERT INTO ".$tablename."(username, password) VALUES ('$username','$password')"); 

Print '<script>alert("Congrats! Your Submission is Successfully Registered!");</script>'; 

?>

AI Generated Answer

AI is thinking...

1.  Develop a simple website that asks the users to register using username, password, and email address. Store these information’s in a database. Use client side script to validate the user input during registration.

10 marks
Details
Official Answer

//index.html

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Form Registration</title>

</head>

<body>

    <h2>Client Side Form Validation</h2>

    <form name="signupForm" onsubmit="return validateForm();" method="POST" action="./formSubmit.php">

        <div>

            <label for="username">Please enter your username: </label>

            <input type="text" name="username" id="username">

        </div>

        <div>

            <label for="password">Please enter your password: </label>

            <input type="password" name="password" id="password">

        </div>

        <div>

            <label for="email">Please enter your email: </label>

            <input type="email" name="email" id="email">

        </div>

        <div>

            <input type="submit" name="signup" value="Signup">

        </div>

    </form>

    <script>

        function validateForm() {

            if (document.signupForm.username.value == "") {

                alert("Please provide your usernamename!");

                document.signupForm.username.focus();

                return false;

            }

            else if (document.signupForm.password.value == "") {

                alert("Please provide your password!");

                document.signupForm.password.focus();

                return false;

            }

          else if (document.signupForm.password.value.length < 8) {

                alert('Password must be at least 8 digit long');

                document.signupForm.password.focus();

                return false;

            }


            else if (document.signupForm.email.value == "") {

                alert("Please provide your Email!");

                document.signupForm.email.focus();

                return false;

            }

            return true;

        }

    </script>

</body>

</html>


//formSubmit.php

<?php

$servername = "localhost";

$username = "root";

$password = "";

$dbname = "webtech";

$tablename = "users";

if($_SERVER["REQUEST_METHOD"] == "POST"){

$username = $_POST['username'];

$password = $_POST['password'];

        $email = $_POST['email'];


//connect to database

$conn = mysqli_connect($servername, $username, $password) or die(mysql_error()); //Connect to server

mysqli_select_db($conn, $dbname) or die("Cannot connect to database"); //Connect to database


        // Insert the values into database

mysqli_query($conn, "INSERT INTO ".$tablename."(username, password, email) VALUES ('$username','$password', '$email')"); 

Print '<script>alert("Congrats! Your Submission is Successfully Registered!");</script>'; 

?>

AI Generated Answer

AI is thinking...

3.  Develop a simple Web site that takes first name, last name and address from the user and stores this information in the database. Use JavaScript to validate form data.

10 marks
Details
Official Answer

//index.html

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Form Registration</title>

</head>

<body>

    <h2>Client Side Form Validation</h2>

    <form name="signupForm" onsubmit="return validateForm();" method="POST" action="./formSubmit.php">

        <div>

            <label for="f_name">Please enter your first name: </label>

            <input type="text" name="f_name" id="f_name">

        </div>

        <div>

            <label for="l_name">Please enter your last name: </label>

            <input type="text" name="l_name" id="l_name">

        </div>

        <div>

            <label for="address">Please enter your address: </label>

            <input type="text" name="address" id="address">

        </div>

        <div>

            <input type="submit" name="signup" value="Signup">

        </div>

    </form>

    <script>

        function validateForm() {

            if (document.signupForm.f_name.value == "") {

                alert("Please provide your first name!");

                document.signupForm.f_name.focus();

                return false;

            }

           else if (document.signupForm.l_name.value == "") {

                alert("Please provide your last name!");

                document.signupForm.l_name.focus();

                return false;

            }

            else if (document.signupForm.address.value == "") {

                alert("Please provide your address!");

                document.signupForm.address.focus();

                return false;

            }

            return true;

        }

    </script>

</body>

</html>


//formSubmit.php

<?php

$servername = "localhost";

$username = "root";

$password = "";

$dbname = "webtech";

$tablename = "users";

if($_SERVER["REQUEST_METHOD"] == "POST"){

$f_name = $_POST['f_name'];

$l_name = $_POST['l_name'];

        $address = $_POST['address'];


//connect to database

$conn = mysqli_connect($servername, $username, $password) or die(mysql_error()); //Connect to server

mysqli_select_db($conn, $dbname) or die("Cannot connect to database"); //Connect to database


        // Insert the values into database

mysqli_query($conn, "INSERT INTO ".$tablename."(f_name,L_name,  address) VALUES ('$f_name', '$l_name', '$address')"); 

Print '<script>alert("Congrats! Your Submission is Successfully Registered!");</script>'; 

?>

AI Generated Answer

AI is thinking...

3.  Prepare a form that should contain text box for name and email, selection list for country. Write a server side script to store data from the form into database. The script should contain connection to database and appropriate query into the database.

10 marks
Details
Official Answer

//index.html

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Form Registration</title>

</head>

<body>

    <form  method="POST" action="formSubmit.php">

        <div>

            <label for="name">Please enter your name: </label>

            <input type="text" name="name" id="name">

        </div>

        <div>

            <label for="email">Please enter email: </label>

            <input type="text" name="email" id="email">

        </div>

        <div>

            <label for="country">Choose your Country: </label>

            <select name="country>"

             <option value="nepal">Nepal</option>

             <option value="china">China</option>

             <option value="india">India</option>

            <option value="usa">USA</option>

            </select>

        </div>

        <div>

            <input type="submit" name="signup" value="Signup">

        </div>

    </form>

</body>

</html>


//formSubmit.php

<?php

$servername = "localhost";

$username = "root";

$password = "";

$dbname = "webtech";

$tablename = "users";

if($_SERVER["REQUEST_METHOD"] == "POST"){

$name = $_POST['name'];

$email = $_POST['email'];

        $country = $_POST['country'];


//connect to database

$conn = mysqli_connect($servername, $username, $password) or die(mysql_error()); //Connect to server

mysqli_select_db($conn, $dbname) or die("Cannot connect to database"); //Connect to database


        // Insert the values into database

mysqli_query($conn, "INSERT INTO ".$tablename."(name, email,  country) VALUES ('$name', '$email', '$country')"); 

Print '<script>alert("Congrats! Your Submission is Successfully Registered!");</script>'; 

?>

AI Generated Answer

AI is thinking...

3. Prepare a form that should contain text box, selection list and radio button. Write PHP script to store data from the form into database using database connection and appropriate query.

10 marks
Details
Official Answer

//index.html

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Form Registration</title>

</head>

<body>

    <form  method="POST" action="formSubmit.php">

        <div>

            <label for="name">Please enter your name: </label>

            <input type="text" name="name" id="name">

        </div>

        <div>

            <label for="email">Please enter email: </label>

            <input type="text" name="email" id="email">

        </div>

        <div>

            <label for="country">Choose your Country: </label>

            <select name="country">

             <option value="nepal">Nepal</option>

             <option value="china">China</option>

             <option value="india">India</option>

            <option value="usa">USA</option>

            </select>

        </div>

        <div>

            <label for="gender">Gender: </label>

            <input type="radio" name="gender" value="male">Male

            <input type="radio" name="gender" value="female">Female

        </div>

        <div>

            <input type="submit" name="signup" value="Signup">

        </div>

    </form>

</body>

</html>


//formSubmit.php

<?php

$servername = "localhost";

$username = "root";

$password = "";

$dbname = "webtech";

$tablename = "users";

if($_SERVER["REQUEST_METHOD"] == "POST"){

$name = $_POST['name'];

$email = $_POST['email'];

        $country = $_POST['country'];

        $gender = $_POST['gender'];


//connect to database

$conn = mysqli_connect($servername, $username, $password) or die(mysql_error()); //Connect to server

mysqli_select_db($conn, $dbname) or die("Cannot connect to database"); //Connect to database


        // Insert the values into database

mysqli_query($conn, "INSERT INTO ".$tablename."(name, email,  country, gender) VALUES ('$name', '$email', '$country', '$gender')"); 

Print '<script>alert("Congrats! Your Submission is Successfully Registered!");</script>'; 

?>

AI Generated Answer

AI is thinking...

1.Create web form for book search catalog. The form should contain a dropdown defining search type, a text box for search keyword, a radio button for download type true or false, now write PHP script to store data from the form into database table and also retrive the results from stored table in a new page.[10]

10 marks
Details
Official Answer

//index.html

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Form Registration</title>

</head>

<body>

    <h2>Book Search Catalog</h2>

     <form  method="POST" action="formSubmit.php">

        <div>

            <label for="country">Choose Search Type: </label>

            <select name="searchtype">

                 <option value="history">History</option>

                 <option value="politics">Politics</option>

                 <option value="childrenbook">Children's Book</option>

                <option value="drama">Drama</option>

               <option value="science">Science</option>

            </select>

        </div>

      <div>

            <label for="name">Please enter name of book: </label>

            <input type="text" name="name" id="name">

        </div> 

        <div>

            <label for="download">Download: </label>

            <input type="radio" name="download" value="true">True

            <input type="radio" name="download" value="false">False

        </div>

        <div>

            <input type="submit" name="submit" value="Submit">

        </div>

    </form>

</body>

</html>


//formSubmit.php

<?php

$servername = "localhost";

$username = "root";

$password = "";

$dbname = "webtech";

$tablename = "books";


if($_SERVER["REQUEST_METHOD"] == "POST"){

$searchtype = $_POST['searchtype'];

$name = $_POST['name'];

        $download = $_POST['download'];


//connect to database

$conn = mysqli_connect($servername, $username, $password) or die(mysql_error()); //Connect to server

mysqli_select_db($conn, $dbname) or die("Cannot connect to database"); //Connect to database

    

    // Insert the values into database

    mysqli_query($conn, "INSERT INTO ".$tablename."(searchtype, name, download) VALUES ('$searchtype', '$name', '$download')");    

Print '<script>alert("Congrats! Your Submission is Successfull!");</script>'; 

Print '<script>window.location.assign("display.php");</script>'; 

}

?>


//display.php

<?php

    $db = "webtech";

    $conn = mysqli_connect("localhost", "root","") or die(mysql_error());

    mysqli_select_db($conn, $db) or die("Cannot connect to database");

    $query = mysqli_query($conn, "Select * from  books"); 

?>

<html>

<head>

    <title>Displaying Data</title>

</head>

<body>

<table border="1">

<tr>

<th>Search Type</th>

<th>Book Name</th>

<th>Download Type</th>

</tr>

    <?php 

     while($row = mysqli_fetch_array($query)) 

{

    ?>   

<tr>

<th><?php echo $row['searchtype']; ?></th>

<th><?php echo $row['name']; ?></th>

<th><?php echo $row['download']; ?></th>

</tr>

<?php } ?>

</table>

<a href="index.html">Go back to Search New Book</a>

</body>

</html>

AI Generated Answer

AI is thinking...

3.  Construct a web page that takes name, address, and phone number from the user and stores this information in the database using server side script. Use JavaScript to validate form data for phone number.

10 marks
Details
Official Answer

//index.html

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Form Registration</title>

</head>

<body>

    <h2>Client Side Form Validation</h2>

    <form name="signupForm" onsubmit="return validateForm();" method="POST" action="./formSubmit.php">

        <div>

            <label for="name">Please enter your name: </label>

            <input type="text" name="name" id="name">

        </div>

        <div>

            <label for="address">Please enter your address: </label>

            <input type="text" name="address" id="address">

        </div>

        <div>

            <label for="phoneNumber">Please enter your PhoneNumber: </label>

            <input type="text" name="phoneNumber" id="PhoneNumber">

        </div>

        <div>

            <input type="submit" name="signup" value="Signup">

        </div>

    </form>

    <script>

        function validateForm() {

            if (document.signupForm.name.value == "") {

                alert("Please provide your name!");

                document.signupForm.name.focus();

                return false;

            }

            else if (document.signupForm.address.value == "") {

                alert("Please provide your address!");

                document.signupForm.address.focus();

                return false;

            }

            else if (document.signupForm.phoneNumber.value == "") {

                alert("Please provide your PhoneNumber!");

                document.signupForm.phoneNumber.focus();

                return false;

            }

            else if (document.signupForm.phoneNumber.value.length < 10) {

                alert('phoneNumber must be at least 10 digit long');

                document.signupForm.name.focus();

                return false;

            }

            return true;

        }

    </script>

</body>

</html>


//formSubmit.php

<?php

$servername = "localhost";

$username = "root";

$password = "";

$dbname = "webtech";

$tablename = "users";

if($_SERVER["REQUEST_METHOD"] == "POST"){

$name = $_POST['name'];

$address = $_POST['address'];

        $phoneNumber = $_POST['phoneNumber'];


//connect to database

$conn = mysqli_connect($servername, $username, $password) or die(mysql_error()); //Connect to server

mysqli_select_db($conn, $dbname) or die("Cannot connect to database"); //Connect to database


        // Insert the values into database

mysqli_query($conn, "INSERT INTO ".$tablename."(name, address, phoneNumber) VALUES ('$name','$address', '$phoneNumber')"); 

Print '<script>alert("Congrats! Your Submission is Successfully Registered!");</script>'; 

?>

AI Generated Answer

AI is thinking...

8.  Discuss the use of Session with suitable example.

5 marks
Details
Official Answer
A session is a way to store information (in variables) to be used across multiple pages. Unlike a cookie, the information is not stored on the users computer rather session is stored in server.
When you work with an application, you open it, do some changes, and then you close it. This is much like a Session. The computer knows who you are. It knows when you start the application and when you end. But on the internet there is one problem: the web server does not know who you are or what you do, because the HTTP address doesn't maintain state.
Session variables solve this problem by storing user information to be used across multiple pages (e.g. username, favorite color, etc.). By default, session variables last until the user closes the browser. So; Session variables hold information about one single user, and are available to all pages in one application.
Fig : For every client session data is stored separately
Uses of session
  • Carrying information as a client travels between pages.
  • One page data can be stored in session variable and that data can be accessed from other pages.
  • Session can help to uniquely identify each client from another
  • Session is mostly used in ecommerce sites where there is shopping cart system.
  • It helps maintain user state and data all over the application.
  • It is easy to implement and we can store any kind of object.
  • Stores client data separately.
  • Session is secure and transparent from the user.
Example:
Start a PHP session
PHP session_start() function is used to start the session. It starts a new or resumes existing session. It returns existing session if session is created already. If session is not available, it creates and returns new session.
E.g.
<?php
// Start the session
session_start();
?>

<!DOCTYPE html>
<html>
<body>
<?php
// Set session variables
$_SESSION["favcolor"] = "green";
$_SESSION["favanimal"] = "cat";
echo "Session variables are set.";
?>

</body>
</html>

GET PHP session variables values
<?php
session_start();
?>

<!DOCTYPE html>
<html>
<body>
<?php
// Echo session variables that were set on previous example
echo "Favorite color is " . $_SESSION["favcolor"] . ".<br>";
echo "Favorite animal is " . $_SESSION["favanimal"] . ".";
?>

</body>
</html>
AI Generated Answer

AI is thinking...

8.  Write an example of server-side script to update data in the database.

5 marks
Details
Official Answer

PHP script to update data in database

Consider a Student table with attribute id, firstname, lastname and email.

Now, update the record with id=2 in the "Student" table:

<?php

$servername = "localhost";

$username = "username";

$password = "password";

$dbname = "myDB";

// Create connection

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection

if ($conn->connect_error) {

  die("Connection failed: " . $conn->connect_error);

}

$sql = "UPDATE Student SET lastname='Poudel' WHERE id=2";

if ($conn->query($sql) === TRUE) {

  echo "Record updated successfully";

} else {

  echo "Error updating record: " . $conn->error;

}

$conn->close();

?>

AI Generated Answer

AI is thinking...

10.  How you can create dynamic content? Explain.

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

11.  Write server-side code to select data stored in the database.

5 marks
Details
Official Answer

PHP code to select data stored in the database

The SELECT statement is used to select data from one or more tables:

    SELECT column_name(s) FROM table_name

or we can use the * character to select ALL columns from a table:

    SELECT * FROM table_name

The following example selects the id, firstname and lastname columns from the MyGuests table and displays it on the page:

<?php

$servername = "localhost";

$username = "username";

$password = "password";

$dbname = "myDB";

// Create connection

$conn = mysqli_connect($servername, $username, $password, $dbname);

// Check connection

if (!$conn) {

  die("Connection failed: " . mysqli_connect_error());

}

$sql = "SELECT id, firstname, lastname FROM MyGuests";

$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {

  // output data of each row

  while($row = mysqli_fetch_assoc($result)) {

    echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";

  }

} else {

  echo "0 results";

}

mysqli_close($conn);

?>

AI Generated Answer

AI is thinking...

11. Write a PHP script that illustrates handling of cookie.

5 marks
Details
Official Answer

<!-- Creating and retrieving the cookie -->

<?php

    $cookie_name = "user";

    $cookie_value = "college_note";

    //86400 = 1 day

    setcookie($cookie_name , $cookie_value, time()+(86400*30),"/");

    if(!isset($_COOKIE[$cookie_name])){

        echo "Cookie named ' " . $cookie_name . " ' is not set!";

    }else{

        echo "Cookie ' " . $cookie_name . " ' is set!<br>";

        echo "Value is : " . $_COOKIE[$cookie_name];

    }

?>

<!-- Deleting the Cookie -->

<?php

    //set the expiration date to one hour ago

    setcookie("user","",time()-3600);

?>

<html>

    <body>

      <?php

        echo "Cookie 'user' is deleted.";

      ?>  

    </body>

</html>

AI Generated Answer

AI is thinking...

11.  Define session. Explain its use with example.

5 marks
Details
Official Answer
A session is a way to store information (in variables) to be used across multiple pages. Unlike a cookie, the information is not stored on the users computer rather session is stored in server.
When you work with an application, you open it, do some changes, and then you close it. This is much like a Session. The computer knows who you are. It knows when you start the application and when you end. But on the internet there is one problem: the web server does not know who you are or what you do, because the HTTP address doesn't maintain state.
Session variables solve this problem by storing user information to be used across multiple pages (e.g. username, favorite color, etc.). By default, session variables last until the user closes the browser. So; Session variables hold information about one single user, and are available to all pages in one application.
Fig : For every client session data is stored separately
Uses of session
  • Carrying information as a client travels between pages.
  • One page data can be stored in session variable and that data can be accessed from other pages.
  • Session can help to uniquely identify each client from another
  • Session is mostly used in ecommerce sites where there is shopping cart system.
  • It helps maintain user state and data all over the application.
  • It is easy to implement and we can store any kind of object.
  • Stores client data separately.
  • Session is secure and transparent from the user.
Example:
Start a PHP session
PHP session_start() function is used to start the session. It starts a new or resumes existing session. It returns existing session if session is created already. If session is not available, it creates and returns new session.
E.g.
<?php
// Start the session
session_start();
?>

<!DOCTYPE html>
<html>
<body>
<?php
// Set session variables
$_SESSION["favcolor"] = "green";
$_SESSION["favanimal"] = "cat";
echo "Session variables are set.";
?>

</body>
</html>

GET PHP session variables values
<?php
session_start();
?>

<!DOCTYPE html>
<html>
<body>
<?php
// Echo session variables that were set on previous example
echo "Favorite color is " . $_SESSION["favcolor"] . ".<br>";
echo "Favorite animal is " . $_SESSION["favanimal"] . ".";
?>

</body>
</html>
AI Generated Answer

AI is thinking...

11.  Why do we need session? Explain with suitable example.

5 marks
Details
Official Answer
A session is a way to store information (in variables) to be used across multiple pages. Unlike a cookie, the information is not stored on the users computer rather session is stored in server.
When you work with an application, you open it, do some changes, and then you close it. This is much like a Session. The computer knows who you are. It knows when you start the application and when you end. But on the internet there is one problem: the web server does not know who you are or what you do, because the HTTP address doesn't maintain state.
Session variables solve this problem by storing user information to be used across multiple pages (e.g. username, favorite color, etc.). By default, session variables last until the user closes the browser. So; Session variables hold information about one single user, and are available to all pages in one application.
Fig : For every client session data is stored separately
Uses of session
  • Carrying information as a client travels between pages.
  • One page data can be stored in session variable and that data can be accessed from other pages.
  • Session can help to uniquely identify each client from another
  • Session is mostly used in ecommerce sites where there is shopping cart system.
  • It helps maintain user state and data all over the application.
  • It is easy to implement and we can store any kind of object.
  • Stores client data separately.
  • Session is secure and transparent from the user.
Example:
Start a PHP session
PHP session_start() function is used to start the session. It starts a new or resumes existing session. It returns existing session if session is created already. If session is not available, it creates and returns new session.
E.g.
<?php
// Start the session
session_start();
?>

<!DOCTYPE html>
<html>
<body>
<?php
// Set session variables
$_SESSION["favcolor"] = "green";
$_SESSION["favanimal"] = "cat";
echo "Session variables are set.";
?>

</body>
</html>

GET PHP session variables values
<?php
session_start();
?>

<!DOCTYPE html>
<html>
<body>
<?php
// Echo session variables that were set on previous example
echo "Favorite color is " . $_SESSION["favcolor"] . ".<br>";
echo "Favorite animal is " . $_SESSION["favanimal"] . ".";
?>

</body>
</html>
AI Generated Answer

AI is thinking...

11.  Discuss the importance of session.

5 marks
Details
Official Answer
A session is a way to store information (in variables) to be used across multiple pages. Unlike a cookie, the information is not stored on the users computer rather session is stored in server.
When you work with an application, you open it, do some changes, and then you close it. This is much like a Session. The computer knows who you are. It knows when you start the application and when you end. But on the internet there is one problem: the web server does not know who you are or what you do, because the HTTP address doesn't maintain state.
Session variables solve this problem by storing user information to be used across multiple pages (e.g. username, favorite color, etc.). By default, session variables last until the user closes the browser. So; Session variables hold information about one single user, and are available to all pages in one application.
Fig : For every client session data is stored separately
Uses of session
  • Carrying information as a client travels between pages.
  • One page data can be stored in session variable and that data can be accessed from other pages.
  • Session can help to uniquely identify each client from another
  • Session is mostly used in ecommerce sites where there is shopping cart system.
  • It helps maintain user state and data all over the application.
  • It is easy to implement and we can store any kind of object.
  • Stores client data separately.
  • Session is secure and transparent from the user.
Example:
Start a PHP session
PHP session_start() function is used to start the session. It starts a new or resumes existing session. It returns existing session if session is created already. If session is not available, it creates and returns new session.
E.g.
<?php
// Start the session
session_start();
?>

<!DOCTYPE html>
<html>
<body>
<?php
// Set session variables
$_SESSION["favcolor"] = "green";
$_SESSION["favanimal"] = "cat";
echo "Session variables are set.";
?>

</body>
</html>

GET PHP session variables values
<?php
session_start();
?>

<!DOCTYPE html>
<html>
<body>
<?php
// Echo session variables that were set on previous example
echo "Favorite color is " . $_SESSION["favcolor"] . ".<br>";
echo "Favorite animal is " . $_SESSION["favanimal"] . ".";
?>

</body>
</html>
AI Generated Answer

AI is thinking...

11.  Write a server-side code to insert data in the database.

5 marks
Details
Official Answer

PHP code to insert data in the database

The INSERT INTO statement is used to add new records to a MySQL table:

    INSERT INTO table_name (column1, column2, column3,...)

    VALUES (value1, value2, value3,...)

The following examples add a new record to the "Student" table:

<?php

$servername = "localhost";

$username = "username";

$password = "password";

$dbname = "myDB";

// Create connection

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection

if ($conn->connect_error) {

  die("Connection failed: " . $conn->connect_error);

}

$sql = "INSERT INTO Student (firstname, lastname, email)

VALUES ('Cristiano', 'Ronaldo', 'cr7@gmail.com')";

if ($conn->query($sql) === TRUE) {

  echo "New record created successfully";

} else {

  echo "Error: " . $sql . "<br>" . $conn->error;

}

$conn->close();

?>

AI Generated Answer

AI is thinking...

12.  Discuss anti-overload techniques in webserver.

5 marks
Details
Official Answer

At any time web servers can be overloaded because of:

  • Too much legitimate web traffic
  • Thousands or even millions of clients hitting the web site in a short interval of time (DDoS) Distributed Denial of Service attacks
  • Computer worms
  • Millions of infected browsers and/or web servers
  • limited on large web sites with very few resources (bandwidth, etc.)
  • Client requests are served more slowly and the number of connections increases so much that server limits are reached
  • Web servers required  urgent maintenance or upgrade
  • Hardware Software failures

To partially overcome load limits and to prevent overload we can use techniques like:

  • Managing network traffic by using: Firewalls, Block unwanted traffic
  • HTTP traffic managers- redirect or rewrite requests having bad HTTP patterns
  • Bandwidth management and traffic shaping
  • Deploying web cache techniques
  • Use different domains to serve different content (static and dynamic) by separate Web servers,
  • Add more hardware resources
  • Use many web servers

These technique to limit the load on websites are called anti-overload techniques in web server.

AI Generated Answer

AI is thinking...

12.  Discuss server side file handling with example.

5 marks
Details
Official Answer

File handling simply deal with creating, reading, deleting and editing files. Website can handle local files. It can read from, and write to, a text file on the disk. The code can run on any server with file system privileges—and also a local development machine

There are some methods of File which are used in PHP:

PHP Open File - fopen():
fopen() function opens the file. The first parameter of fopen() contains the name of the file to be opened and the second parameter specifies in which mode the file should be opened. E.g.
    $myfile = fopen("webdictionary.txt""r"

PHP Read File - fread():
The fread() function reads from an open file. The first parameter of fread() contains the name of the file to read from and the second parameter specifies the maximum number of bytes to read. The following PHP code reads the "webdictionary.txt" file to the end:
    fread($myfile,filesize("webdictionary.txt"));

PHP Close File - fclose():
The fclose() function is used to close an open file. E.g.
    fclose($myfile);

PHP Write to File - fwrite():
The fwrite() function is used to write to a file. The first parameter of fwrite() contains the name of the file to write to and the second parameter is the string to be written. E.g.
<?php
$myfile = fopen("newfile.txt""w"or die("Unable to open file!");
$txt = "Hello bro!\\n";
fwrite($myfile, $txt);
fclose($myfile);
?>
AI Generated Answer

AI is thinking...

12.  How session handling is done in server side scripts?

5 marks
Details
Official Answer
A session is a way to store information (in variables) to be used across multiple pages. Unlike a cookie, the information is not stored on the users computer rather session is stored in server.
When you work with an application, you open it, do some changes, and then you close it. This is much like a Session. The computer knows who you are. It knows when you start the application and when you end. But on the internet there is one problem: the web server does not know who you are or what you do, because the HTTP address doesn't maintain state.
Session variables solve this problem by storing user information to be used across multiple pages (e.g. username, favorite color, etc.). By default, session variables last until the user closes the browser. So; Session variables hold information about one single user, and are available to all pages in one application.
Fig : For every client session data is stored separately

In PHP session is handled as follows:
PHP session_start() function is used to start the session. It starts a new or resumes existing session. It returns existing session if session is created already. If session is not available, it creates and returns new session.
PHP $_SESSION is an associative array that contains all session variables. It is used to set and get session variable values. For e.g.
Store information: $_SESSION["user"] = "Jayanta"
Get information: echo $_SESSION["user"];  

Example:
Set PHP session variables values
<?php
// Start the session
session_start();
?>

<!DOCTYPE html>
<html>
<body>
<?php
// Set session variables
$_SESSION["favcolor"] = "green";
$_SESSION["favanimal"] = "cat";
echo "Session variables are set.";
?>

</body>
</html>

GET PHP session variables values
<?php
session_start();
?>

<!DOCTYPE html>
<html>
<body>
<?php
// Echo session variables that were set on previous example
echo "Favorite color is " . $_SESSION["favcolor"] . ".<br>";
echo "Favorite animal is " . $_SESSION["favanimal"] . ".";
?>

</body>
</html>
AI Generated Answer

AI is thinking...

12.  Discuss integrated window authentication.

5 marks
Details
Official Answer
Authentication is the process of determining the identity of a user based on the user’s credentials. The user’s credentials are usually in the form of user ID and password, which is checked against any credentials' store such as database. If the credentials provided by the user are valid, then the user is considered an authenticated user.

Window Authentication is the way in which authentication is performed. It provides information on how to use Windows authentication in conjunction with Microsoft Internet Information Services (IIS) authentication to secure ASP.NET applications. This is the default authentication mode in ASP.NET and it is set in web.config file of the application.

Windows Authentication uses the security features of Windows clients and servers. Unlike Basic authentication, initially, it does not prompt users for a user name and password. The current Windows user information on the client computer is supplied by the web browser through a cryptographic exchange involving hashing with the Web server. If the authentication exchange initially fails to identify the user, the web browser will prompt the user for a Windows user account user name and password.

Windows authentication is generally used if the users accessing the application belong to same organization. This authentication method uses Windows accounts for validating users' credentials. This type of authentication is very good for intranet Web sites where we know our users.
AI Generated Answer

AI is thinking...

12.  What are anti-overloaded techniques in web server?

5 marks
Details
Official Answer

At any time web servers can be overloaded because of:

  • Too much legitimate web traffic
  • Thousands or even millions of clients hitting the web site in a short interval of time (DDoS) Distributed Denial of Service attacks
  • Computer worms
  • Millions of infected browsers and/or web servers
  • limited on large web sites with very few resources (bandwidth, etc.)
  • Client requests are served more slowly and the number of connections increases so much that server limits are reached
  • Web servers required  urgent maintenance or upgrade
  • Hardware Software failures

To partially overcome load limits and to prevent overload we can use techniques like:

  • Managing network traffic by using: Firewalls, Block unwanted traffic
  • HTTP traffic managers- redirect or rewrite requests having bad HTTP patterns
  • Bandwidth management and traffic shaping
  • Deploying web cache techniques
  • Use different domains to serve different content (static and dynamic) by separate Web servers,
  • Add more hardware resources
  • Use many web servers

These technique to limit the load on websites are called anti-overload techniques in web server.

AI Generated Answer

AI is thinking...

12.  Discuss about authentication by IP addressing and domain.

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

13.  Explain the form handling with example.

5 marks
Details
Official Answer

Handling forms is a multipart process. First a form is created, into which a user can enter the required details. This data is then sent to the web server, where it is interpreted, often with some error checking.

PHP Form Handling with POST

If we specify the form method to be POST, then the form-data is sent to the server using the HTTP POST method.

syntax:

<?php

 $_POST['variable_name'];

?>

E.g. 

//form1.html

<form action="login.php" method="post">   

<table>   

<tr><td>Name:</td><td> <input type="text" name="name"/></td></tr>  

<tr><td>Password:</td><td> <input type="password" name="password"/></td></tr>   

<tr><td colspan="2"><input type="submit" value="login"/>  </td></tr>  

</table>  

</form>   

//login.php

<?php  

$name=$_POST["name"];   //receiving name field value in $name variable  

$password=$_POST["password"];   //receiving password field value in $password variable  

echo "Welcome: $name, your password is: $password";  

?>  

PHP Form Handling with GET

If we specify the form method to be GET, then the form-data is sent to the server using the HTTP GET method.

syntax:

<?php

$_GET['variable_name'];

?>

E.g. 

//form1.html

<form action="welcome.php" method="get">  

    Name: <input type="text" name="name"/>  

    <input type="submit" value="visit"/>  

</form>  

//welcome.php

<?php  

$name=$_GET["name"];    //receiving name field value in $name variable  

echo "Welcome, $name";  

?>  

AI Generated Answer

AI is thinking...

13.  Differentiate between file handling and form handling.


5 marks
Details
Official Answer

File handling

File handling simply deal with creating, reading, deleting and editing files. Website can handle local files. It can read from, and write to, a text file on the disk. The code can run on any server with file system privileges—and also a local development machine
There are some methods of File which are used in PHP:

PHP Open File - fopen():
fopen() function opens the file. The first parameter of fopen() contains the name of the file to be opened and the second parameter specifies in which mode the file should be opened. E.g.
    $myfile = fopen("webdictionary.txt""r"

PHP Read File - fread():
The fread() function reads from an open file. The first parameter of fread() contains the name of the file to read from and the second parameter specifies the maximum number of bytes to read. The following PHP code reads the "webdictionary.txt" file to the end:
    fread($myfile,filesize("webdictionary.txt"));

PHP Close File - fclose():
The fclose() function is used to close an open file. E.g.
    fclose($myfile);

PHP Write to File - fwrite():
The fwrite() function is used to write to a file. The first parameter of fwrite() contains the name of the file to write to and the second parameter is the string to be written. E.g.
<?php
$myfile = fopen("newfile.txt""w"or die("Unable to open file!");
$txt = "Hello bro!\\n";
fwrite($myfile, $txt);
fclose($myfile);
?>

Form Handling

Handling forms is a multipart process. First a form is created, into which a user can enter the required details. This data is then sent to the web server, where it is interpreted, often with some error checking.

PHP Form Handling with POST:

If we specify the form method to be POST, then the form-data is sent to the server using the HTTP POST method.

syntax:

<?php

 $_POST['variable_name'];

?>

E.g. 

//form1.html

<form action="login.php" method="post">   

<table>   

<tr><td>Name:</td><td> <input type="text" name="name"/></td></tr>  

<tr><td>Password:</td><td> <input type="password" name="password"/></td></tr>   

<tr><td colspan="2"><input type="submit" value="login"/>  </td></tr>  

</table>  

</form>   

//login.php

<?php  

$name=$_POST["name"];   //receiving name field value in $name variable  

$password=$_POST["password"];   //receiving password field value in $password variable  

echo "Welcome: $name, your password is: $password";  

?>  

PHP Form Handling with GET:

If we specify the form method to be GET, then the form-data is sent to the server using the HTTP GET method.

syntax:

<?php

$_GET['variable_name'];

?>

E.g. 

//form1.html

<form action="welcome.php" method="get">  

    Name: <input type="text" name="name"/>  

    <input type="submit" value="visit"/>  

</form>  

//welcome.php

<?php  

$name=$_GET["name"];    //receiving name field value in $name variable  

echo "Welcome, $name";  

?>  

AI Generated Answer

AI is thinking...

13.  Write short notes on:

a.       Tag libraries

b.      Anonymous access


5 marks
Details
Official Answer

a. Tag Libraries

In a Web application, a common design goal is to separate the display code from business logic. Java tag libraries are one solution to this problem. Tag libraries allow you to isolate business logic from the display code by creating a Tag class (which performs the business logic) and including an HTML-like tag in your JSP page. When the Web server encounters the tag within your JSP page, the Web server will call methods within the corresponding Java Tag class to produce the required HTML content.

A tag library defines a collection of custom actions. The tags can be used directly by developers in manually coding a JSP page, or automatically by Java development tools. A tag library must be portable between different JSP container implementations.

A custom tag library is made accessible to a JSP page through a taglib directive of the following general form:

<%@ taglib uri="URI" prefix="prefix" %>

b. Anonymous access

Authentication is the process of determining the identity of a user based on the user’s credentials. The user’s credentials are usually in the form of user ID and password, which is checked against any credentials' store such as database. If the credentials provided by the user are valid, then the user is considered an authenticated user.

In Anonymous Access, there is no authentication performed and the user is treated as anonymous user by Internet Information Services (IIS)Sometimes it is necessary or possible to access any data from remote server or database without any authenticated person. If the data is easily accessible without any authentication (i.e username and password) that means the user accessing those data or file has an anonymous access. There is no difference between a user who is “anonymously authenticated” and an unauthenticated user. There can be many situations where anonymous authentication is useful.
AI Generated Answer

AI is thinking...

13.  Write short notes on:

a.       X Query

b.      Tag libraries

5 marks
Details
Official Answer

a.  XQuery

XQuery is a functional query language used to retrieve information stored in XML format. It is same as for XML what SQL is for databases. It was designed to query XML data.

XQuery is built on XPath expressions. It is a W3C recommendation which is supported by all major databases.

E.g.

for $x in doc("books.xml")/bookstore/book
where $x/price>30
order by $x/title
return $x/title


b. Tag Libraries

In a Web application, a common design goal is to separate the display code from business logic. Java tag libraries are one solution to this problem. Tag libraries allow you to isolate business logic from the display code by creating a Tag class (which performs the business logic) and including an HTML-like tag in your JSP page. When the Web server encounters the tag within your JSP page, the Web server will call methods within the corresponding Java Tag class to produce the required HTML content.

A tag library defines a collection of custom actions. The tags can be used directly by developers in manually coding a JSP page, or automatically by Java development tools. A tag library must be portable between different JSP container implementations.

A custom tag library is made accessible to a JSP page through a taglib directive of the following general form:

<%@ taglib uri="URI" prefix="prefix" %>
AI Generated Answer

AI is thinking...

10. How can you define variables in PHP? Define any two variable of string types and display their results after concatenation.[1+4]

5 marks
Details
Official Answer

In PHP, a variable is declared using a $ sign followed by the variable name. 

        $variablename = value;

E.g.

    $str="hello string";

    $x=200;

    $y=44.6;


Second Part:

<?php

       $fname = 'Jayanta';     // First String

       $lname = 'Poudel';     // Second String

       $fullname = $fname." ".$lname;    // Concatenation Of String

       echo " $fullname \\n";     // print Concatenate String

?>

AI Generated Answer

AI is thinking...