Mp QA 1
Mp QA 1
Mp QA 1
Section A
I. Answer any four each carries 2 marks (4*
2=8)
1.Define www or the web ?
Ans : The world wide web (or web) is a system of interlinked hypertext
documents accessed via the internet .These documents are created organized
and linked together using standard technologies like ,HTML ,HTTP , and
URL .The interconnected document may be located on one or more computer
worldwide , which is why it is called world wide web .The interconnected are
accessed using web browsers , like google, chrome, Mozilla , Fire fox etc.
2. what is MIME ?
Ans: MIME or Multipurpose Internet Mail Extensions is a specification that
helps different software system communication with each other over the internet.
It does this by specifying the types of being exchanged ,such as text, images
,audio ,video and application programmes .This is important because different
types of files required different method of interpretation and display.
A MIME type is comprised as : primarty_type/subtype
Ex: text/html.
3. What do you mean by absolute positing of an element?
Ans: The absolute position in CSS is a power full property that allows for precise
placement of an element within a web page ,independent of the normal flow of
document content.
4. what is xml schema ? what are the difference b/w DTD and schema?
Ans: xml schema is also known as XSD is way to define the structure ,content
and data types of xml documents. It provides a mean to specify the elements ,
attributes and there relationship with an xml document as well as the allow data
types of the content of elements.
5. Logging and Monitoring: A web server can log user activity and monitor
server performance to help identify and troubleshoot issues.
6. Running Applications: A web server can run applications such as content
management systems, e-commerce platforms, and other web-based software.
Example: Let's say that the document contains a <div> which contains a
<p> which contains an <img>. Further, let's say we have added an event
listener to all of them. When a user clicks on the image, a
mouseclick event occurs.
Even though the user clicked the image, the image doesn't get the event first.
Instead, the event listener attached to the document grabs the event first and
processes it. (That is, it captures the event before it gets to its intended target
<img>.) The event is then passed down to the <div>'s event listener. The event
then goes to the <p>, and finally to the <img>. That is, all of the clicked-on
object's "ancestors" higher up in the document capture the event for processing
before sending it down the chain to its intended target.
2 Bubbling: Bubbling is the most common type of event propagation. When an
event occurs on an element, it is first handled by that element, and then it
"bubbles up" to its parent element, and then to its parent's parent, and so on, until
it reaches the top of the DOM hierarchy (i.e., the document object).
Example: We have an <img> inside a <p>, which is inside a <div>, which is
inside the document. When a user clicks the image, this time the events rise like a
bubble in a glass of water. The click's original target, the <img>, gets to see the
event first and it processes, and then passes it upwards to the <p> for further
processing, which passes it on to the <div>, which finally passes it up to the
document for processing.
9.Explain SAX and DOM parses . what are the main differences of SAX and
DOM?
ANS: XML documents are used in practically every application in the world
today. The XML document required for electronic processing and manipulation.
This is accomplished with a parser, which responsible for scanning the document,
identifying the various elements in it, and making these elements and the data
they contain available for further electronic processing.
Two Major Techniques for XML Parsing: SAX and DOM
There are two major techniques available for XML parsing:
1. Simple API for XML (SAX): This is an event-based parsing. The parser
generates an application event whenever it encounters an element or data in the
document being parsed. As its name indicates, SAX really is a simple API for
processing XML documents, SAX is event based as the document is processed.
SAX generates events for the use of the processing application Such events
indicate the beginning of the document, the end of the document, each element
occurrence, and so on. For example, when XML file is parsed, an event will be
generated whenever the parser encounters an element such as <title> or <title>.
Because the events am generated while the document is being parsed, we do not
have to wait for the entire document to be read before processing occurs.
Document Object Model (DOM) in this model, the parser builds an in-memory
structure for the entire document that is parsed. We can then traverse the memory
tree structure to visit various nodes, examine their contents, modify their
contents, and more. Because the entire document tree is available in memory, we
can use the DOM API to navigate the tree, modify the document contents, and
store the modified document into another XML. file. We can also add a nodes,
delete nodes, add and delete attributes, and perform other tasks to the in-memory
tree we save the document before tree to an external file.
The differences are:
DOM SAX
A DOM (Document Object Model) A SAX (Simple API for XML) parser
parser creates a tree structure in does not create any internal structure.
memory from an input document and Instead, it takes the occurrences of
then waits for requests from client. components of an input document as
events, and tells the client what it
reads as it reads through the input
document.
2. Dynamic Typing: Dynamic typing in PHP allows variables to change their data
type based on the value assigned to them. This means that a variable can hold
different data types at different points in the code execution.
For example, a variable initially assigned an integer value can later be assigned a
string value, and PHP accommodates this change without requiring explicit type
declaration.
$Value = 10;
$Value = “Hello”
In this example, $value starts as an integer. Later, when it's assigned a string,
PHP dynamically changes its type to a string. This feature allows variables in
PHP to be very flexible.
Type Juggling : Type juggling refers to PHP's behavior of automatically
converting variables to the appropriate data type when they are used in
operations or comparisons. For instance, when a string representing a number is
used in an addition operation, PHP intelligently converts the string to an integer
or float to perform the arithmetic operation.
$num = 10;
$result = $num + 5;
echo $result;
In this example, $num is initially a string. However, when it's used in an addition
operation with an integer (5), PHP performs type juggling by treating $num
as an integer to carry out the addition.
11. Explain call by value and by call reference in php with exmples ?
Ans: When a function argument is passed by value, a copy of the argument's
value is created and passed to the function Any changes made to the argument
within the function do not affect the original value of the argument outside the
function.
Example Call by Value Output
<?php 65
function increment($num) {
$num++;
return $num;
}
$Value = 5;
echo increment($value);
echo $value;
?>
When a function argument is passed by value, a copy of the argument sto hot
affect the and passed to When a function argument is the argument within the
function do not the original value of the argument outside the function.
12. Explain the purpose of array_push() , array_pop() , array_merge() ,
array_keys() , and array_values() in php ?
Ans:
Function And Description Example
array_push(): $arr = [1, 2];
Adds one or more elements to the end array_push($arr, 3, 40);
of an array. Commonly used for print_r($arr);
dynamically expanding an array.
Output: Array ( [0] => 1 [1] => 2 [2]
=> 3 [3] => 48)
array_values(): $arr["a" => 10, "b" => 20, "c" => 30];
Extracts all the values of an array and $values = array_values($arr);
returns them as a new array Used for print_r($values);
obtaining just the values from an array. Output: Array ( [0] => 10 [1] => 20
[2] => 30 )
Section C
Answer any four each carries 8 marks (4*8 = 32)
13 . Explain DOM2 Event Model .Key Features of the DOM 2 Event Model?
Ans: The DOM 2 Event Model :
The DOM 2 event model is a standard for handling events in web browsers. It is
an improvement over the original DOM event model ,which had some limitation
and inconsistencies. The DOM 2 event model defines a standard set of event
types and provide a way to register event listeners for those events. DOM 2
event model is supported by most modern web browsers and is widely used in
web development.
While the DOM O model is still widely supported and used, the DOM 2 model
introduces a more modular and flexible way to manage events, with better
support for a wider range of event types and interactions.
KEY FEATURES OF THE DOM 2 EVENT MODEL:
1. Standard Event Types: The DOM 2 event model defines a standard set of event
types, such as click, mouseover, and keydown. This makes it easier for
developers to write cross-browser code that works consistently across different
platforms.
2. Event Listeners: The DOM 2 event model provides a way to register event
listeners for specific events. This allows developers to write code that responds to
user actions, such as clicking a button or typing in a text field.
3. Event Propagation: The DOM 2 event model introduces the concept of event
propagation, which allows events to be handled at different levels of the
document hierarchy. This means that an event can be handled by an element's
parent, grandparent, or even higher up in the document tree.
4. Event Object: The DOM 2 event model provides an event object that contains
information about the event, such as the target element, the type of event, and
any data associated with the event.
if(!($num1 == $num2))
{
echo "The conditions are not equal";
}
String String operators are $str1 = "Hello";
operator used to concatenate
$str2 = "World";
strings or perform other
operations on strings in // Output: Hello World echo $str1.
PHP. The two basic $str2;
string operators in PHP
are the concatenation str1 = "Hello";
operator . $str2 = "World";
$str1 .= "" $str2;
echo $str1; // Output: Hello World
15.Explain Simple types and Complex types of Xml Schema with example?
Ans: Simple-type:
Simple-type elements have no children or attributes. For example, the Name
element below is a simple-type element; whereas the Person and HomePage
elements are not. A simple-type element is defined using the type attribute in
Scheme Definition.
• Data types that are already defined in XML schema specification and ready to
use in schema to declare elements and attributes are known as built-in data types.
XML Schema provides many built-in data types.
*primitive data:
1 Boolean 2. String 3.Decimal 4. Float
*Built in derived data:
1.Token 3.language 4.Name 5.Entity
*Data deived from decimal primitive data:
1.Integer 2.Non positive integer 3.Negetive integer 4.Int
Example: In the below code, we have used xs:string for FirstName and
LastName, xs:integer for Age, xs:date for DOB, and xs:float for Percentage.
They are not explicitly defined as simple type elements. Instead, the type is
defined with the type attribute. Because the value (string, integer,date, and float)
is a simple type, the elements themselves are simple-type elements.
• A complex-type element can be empty, contain simple content such as a string,
or can contain complex content such as a sequence of elements. It is not
necessary to explicitly declare that a simple-type element is a simple type, but it
is necessary to specify that a complex-type element is a complex type.
• Content Models: Content models are used to indicate the structure and order in
which child elements can appear within their parent element. Content models are
made up of model groups.
The three types of model groups are listed below.
1. xs:sequence - the elements must appear in the order specified.
2. xs:all - the elements must appear, but order is not important.
3. xs:choice - only one of the elements can appear.
> xs:sequence: The following sample shows the syntax for declaring a complex-
type element as a sequence, meaning that the elements must show up in the order
they are declared.
> xs:all : The following sample shows the syntax for declaring a complex-type
element as a conjunction.
> xs:choice: The following sample shows the syntax for declaring a complex-
type element as a choice.
16. Explain conditional statements in php , including if ,if else ,elseif , neasted if
and switch statements?
Ans: Conditional Statements in PHP
Sometimes when you write code, you want to perform different actions for
different decisions. You can use conditional statements in your code to do this.
The conditional statements are the set of commands used to perform different
actions based on different conditions.
PHP If Statement
Compound If Statements: You may also compound the statements using elseif to have
multiple conditions tested insequence. You should use this construction if you want to select
one of many sets of lines toexecute.
<?php
$num1 = 12;
$num2 = 15; $num3=20; if ( ( $num1 <$num2) && ($num2<$num3)
)//Using Compound If Statement
{
echo “$num1 is 12, $num2 is 15 and $num3 is 20";
}
?>
PHP If-else Statement
PHP if-else statement is executed whether condition is true or false. If-else statement is
slightly different from if statement. It executes one block of code if the specified condition is
true and another block of code if the condition is false. The syntax if-else statement is:
if (condition)
{
statements_1
} else {
statements_2
}
The Nested if contains the if block inside another if block. Here, the inner if statement
executes only when specified condition in outer if statement is true. The syntax for the
Nested if is:
if (condition) {
//code to be executed if condition is true if
(condition) {
//code to be executed if condition is true
Switch Statement in PHP
Switch statements work the same as if statements. However, the difference is that they can
check for multiple values. Of course you do the same with multiple if..else statements, but
this is not always the best approach.A switch statement allows a program to evaluate an
expression and attempt to match the expression’s value to a case label. If a match is found,
the program executes the associated statement. One can use the switch statement to select
one of many blocks of code to be executed. Syntax:
Switch (expression)
{
Case label1:
code to be executed if expression = label1; break;
Case label2:
code to be executed if expression = label2; break;
default:
Code to be executed if expression is different
from both label1 and label2;
}
Numerically indexed arrays in PHP have several key features that make them a fundamental data
structure for storing and manipulating ordered collections of elements. The key features of
numerically indexed arrays are:
1. Ordered Collection: Numerically indexed arrays maintain the order of elements based on their
numeric indices. Elements are stored and accessed based on their position within the array, starting
from index 0.
2. Sequential Access: Elements in a numerically indexed array can be accessed sequentially using
numeric indices. This allows for efficient iteration over the elements using loops or other iterative
constructs
3. Zero-Based Indexing: The indices of numerically indexed arrays start from 0, with subsequent
elements being assigned indices incrementally (1, 2, 3, and so on). This zero-based indexing is a
fundamental characteristic of numerically indexed arrays in PHP.
4. Array Functions: PHP provides a rich set of array functions that are well-suited for numerically
indexed arrays. These functions include 'count()' for determining the number of elements, array.
push' and 'array.pop()' for adding and removing elements, and 'array_slice()' for extracting a
portion of the array.
5. Memory Efficiency: Numerically indexed arrays are memory-efficient and provide constant-time
access to elements based on their indices. This makes them suitable for scenarios where fast access
to elements by position is required.
6. Flexible Data Types: Elements within a numerically indexed array can be of any data type,
allowing for the storage of integers, strings, objects, or even nested arrays within a single array
structure.
7. Array Iteration: Numerically indexed arrays can be easily iterated using loops such as 'for',
'foreach or 'while', allowing for convenient traversal and processing of array elements.
Syntax $arrayName[Index];
18.Explain the process of reading from and writing files in php with an example
code?
Ans: Writing to Files
In PHP, writing to files is a fundamental operation that allows developers to store data persistently.
This capability is crucial for tasks like logging, exporting data, saving user-generated content, and
creating configuration files. The process typically involves opening a file, writing to it, and then closing
it. This can be achieved using functions such as fwrite() and file_put_contents().
fwrite(): <?php
The 'fwrite' function is used to $file = fopen("example.txt", "w");
write data to a file. It takes two
parameters: the file handle returned if ($file)
by 'fopen' and the data to be written {
to the file. If the write operation is
successful, ?> 'fwrite' returns the fwrite($file, "Hello, World!");
number of bytes written;
fclose($file);
Otherwise, it returns 'false'.
}
?>
This script opens "example.txt" for writing
and writes
"Hello, World!" into it.
file_put_contents(): <?php
The 'file_put_contents function is a $text "Web Programming":
simpler way to write data to a file. It
takes two parameters: the file name file_put_contents("example.txt",$text);
or path, and the data to be written to ?>
the file. If the write operation is
successful. file put contents' returns In this example, the content "Web
the number of bytes written; Programming" is written to the file
otherwise, it returns 'false' "example.txt". This function handles the
opening writing, and closing of the file
internally
2. Reading the File: There are several methods to read from a file in PHP:
3. Checking End of File (EOF): While reading a file, it's important to check whether the end of the
file has been reached. The feof() function is used for this purpose in a loop to continue reading until the
end of the file.
4. Closing the File: After reading, close the file using fclose(). This is important for freeing up system
resources.
file_get_contents(): <?php
$content=file_get_contents(“example.text”);
echo $content;
?>
In this example, reads the entire content of
“example.txt” and stores it in
$content,which is then echoed
fread(): <?php
Reads up to a specified length from $file = fopen("example.txt","r");
a ?5 file. Used in conjunction with
fopen(). if ($file)
{
$content = fread($file, 100);
echo $content;
fclose($file);
}
?>
The fopen() function opens "example.txt" in
read-only mode. The fread(Sfile, 100) reads
the first 100 bytes of the file. If the file is
smaller than 100 bytes, it reads until the end
of the file.
The script outputs the read content, which
could be part of a file, a full file if it's less
than 100 bytes, or nothing if the file can't be
opened or is empty.
file(): <?php
$lines = file("example.txt");
foreach ($lines as $line)
Reads the entire file into an array, {
with each line as an element of the
array. Useful for processing files echo $line;
line by line. }
?>
This reads example.txt into an array and
prints each line
fgetc(): <?php
Reads a single character from the $file fopen("example.txt", "");
file at a time. Useful for character-
by- character file processing if ($file)
{
while ((Scharfgetc($file)) !== false)
{
echo $char;
}
fclose($file);
}
?>
In this example, "example.txt" is opened and
read character by character using fgetc().
Each character is echoed until EOF is
reached