Unit-4 Introduction to XML
Unit-4 Introduction to XML
DTD and Schemas, Using XML with application. Transforming XML using XSL and
XSLT PHP: Introduction and basic syntax of PHP, decision and looping with examples,
PHP and HTML, Arrays, Functions, Browser control and detection, string, Form
processing, Files, Advance Features: Cookies and Sessions, Object Oriented Programming
with PHP.
XML Example
<bookstore>
<book>
<title>Learning XML</title>
<author>John Doe</author>
</book>
</bookstore>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/X
SL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Book Titles</h2>
<ul>
<xsl:for-each
select="bookstore/book">
<li><xsl:value-of
select="title"/></li>
</xsl:for-each>
</ul>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
PHP (Hypertext Preprocessor) :
1. Introduction and Basic Syntax of PHP: PHP is a server-side scripting language
designed specifically for web development. Its’ embedded within HTML and
executed on server. Basic PHP Syntax:
<?
Echo “Hellow, World”;
?>
PHP (Hypertext Preprocessor)
1. Introduction and Basic Syntax of PHP: PHP is a server-side scripting language
designed for web development but also used as a general-purpose programming
language.
2. Decision and Looping with Examples: Conditional statements like if, else, and loops
like for, while, and foreach.
3. PHP and HTML: Embedding PHP within HTML to create dynamic web pages.
4. Arrays: Storing multiple values in a single variable, with array functions for sorting,
merging, and more.
5. Functions: Creating reusable blocks of code with PHP functions.
6. Browser Control and Detection: Handling browser-specific functionality and
detecting browser types.
7. String Handling: Manipulating text strings with PHP functions.
8. Form Processing: Handling form data sent via POST or GET.
9. Files: Reading from and writing to files on the server.
10. Advanced Features:
o Cookies and Sessions: Managing user data across sessions and maintaining
state.
o Object-Oriented Programming (OOP) with PHP: Using classes, objects,
inheritance, and other OOP concepts.
Q.1]. What is XML schema? State its purpose and its advantages over DTD. (AL Nov-
2023)
XML Schema एक शक्तिशाली तरीका है XML दस्तावेज़ों की संरचना,
सामग्री और अर्थ को परिभाषित करने का। यह DTD (Document Type
Definition) की तुलना में अधिक मज़बूत और बहुमुखी है।
उद्देश्य:
मान्यता: यह सुनिश्चित करता है कि XML दस्तावेज़ परिभाषित
संरचना और डेटा प्रकारों का पालन करें।
डेटा प्रकार: तत्वों और गुणों के लिए डेटा प्रकारों (जैसे,
string, integer, date) को परिभाषित करता है।
Namespace समर्थन: XML namespaces को संभालता है, जिससे कई
schemas के तत्वों और गुणों को मिलाया जा सकता है।
DTD के ऊपर फायदे:
1. डेटा प्रकार: XML Schema डेटा प्रकारों का समर्थन प्रदान
करता है, जैसे integer, string, date आदि, जिससे अधिक सटीक डेटा
मान्यता संभव है।
2. Namespaces: XML Schema XML namespaces का समर्थन करता है, जो
DTD नहीं करता, जिससे अधिक जटिल और पुन: प्रयोज्य दस्तावेज़
परिभाषाएँ संभव हैं।
3. विस्तारशीलता: XML Schema अधिक विस्तारशील है और जटिल डेटा
संरचनाओं का वर्णन कर सकता है।
4. उत्तराधिकार और बहुरूपता: XML Schema जटिल प्रकारों को
अन्य प्रकारों से विरासत में लेने की अनुमति देता है, जिससे
दस्तावेज़ संरचनाओं को परिभाषित करने में अधिक लचीलापन
मिलता है।
5. मजबूत मान्यता: XML Schema डेटा प्रकारों और बाधाओं (जैसे,
न्यूनतम और अधिकतम मान) के माध्यम से मजबूत मान्यता
क्षमताएँ प्रदान करता है।
6. समृद्ध डेटा प्रकारों का समर्थन: DTD, जो केवल सीमित सेट के
डेटा प्रकारों का समर्थन करता है, के विपरीत, XML Schema
उपयोगकर्ता-परिभाषित डेटा प्रकारों और बाधाओं को परिभाषित
कर सकता है।
XML Shema is powerful way to define the structure, content, and semantics of XML
documents. It is more robust and versatile compared to DTD (Document type Definition).
XML Schema
XML Schema is a powerful way to define the structure, content, and semantics of XML
documents. It is more robust and versatile compared to DTD (Document Type Definition).
Purpose:
Validation: Ensures that the XML document adheres to the defined structure and
data types.
Data Typing: Defines data types for elements and attributes (e.g., string, integer,
date).
Namespace Support: Handles XML namespaces, allowing elements and attributes
from multiple schemas to be mixed.
Advantages over DTD:
1. Data Types: XML Schema provides support for data types, such as integers, strings,
dates, etc., enabling more precise data validation.
2. Namespaces: XML Schema supports XML namespaces, which DTD does not, allowing
for more complex and reusable document definitions.
3. Extensibility: XML Schema is more extensible and can describe complex data
structures.
4. Inheritance and Polymorphism: XML Schema allows complex types to inherit from
other types, providing greater flexibility in defining document structures.
5. Stronger Validation: XML Schema offers stronger validation capabilities through data
types and constraints, such as minimum and maximum values.
6. Support for Rich Data Types: Unlike DTD, which only supports a limited set of data
types, XML Schema can define user-defined data types and constraints.
Q.2]. What is XML? What are the attributes of XML? (CY May-2023) (AD
2022) (CS 2020)
XML (Extensible Markup Language) is a versatile markup language used for storing and
transporting data.
Attributes of XML:
Q.3]. Explain the different components of DTD with example. (CS 2020)
DTD (Document Type Definition) specifies the structure and rules for XML documents.
Components:
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
<!ATTLIST note date CDATA #REQUIRED>
]>
Q.4]. Compare the critical differences between DTD and XML. (CS Nov-
2023)
Data Types: XML Schema supports a wide range of data types; DTD does not.
Syntax: XML Schema uses XML syntax; DTD uses a different syntax.
Namespaces: XML Schema supports namespaces; DTD does not.
Complexity: XML Schema can handle more complex structures.
Validation: XML Schema provides stronger validation mechanisms.
comparison between DTD and XML Schema in tabular format:
Inheritance and
Not supported Supported
Polymorphism
This table highlights the main differences between DTD and XML Schema,
Q.5]. Briefly explain XSL transformation with an example of script. (CS Nov-
2023)
SL Transformation (XSLT)
Key Benefits
Arrays
Functions
Strings
Form Processing
Files
Example Code
<?php
// Variable declaration
$name = 'John Doe';
// Conditional statement
if ($name == 'John Doe') {
echo 'Hello, John!';
}
// Loop
for ($i = 0; $i < 5; $i++) {
echo 'Iteration ' . $i . '<br>';
}
// Array
$fruits = array('Apple', 'Banana', 'Cherry');
echo $fruits[0]; // Output: Apple
// Function
function greet($name) {
echo 'Hello, ' . $name . '!';
}
greet('Jane Doe'); // Output: Hello, Jane Doe!
?>
Q.7]. Discuss about various types of PHP interpreters. Write a program in PHP
to find out the length of the string “This my first program”. (AL Nov-2023)
Types of PHP Interpreters
1. Zend Engine:
o The default PHP interpreter.
o Used in most PHP installations.
o Provides a robust and efficient way to execute PHP code.
2. HHVM (HipHop Virtual Machine):
o Developed by Facebook.
o Uses a Just-In-Time (JIT) compilation approach to enhance performance.
o Known for faster execution of PHP scripts compared to Zend Engine.
3. Phalanger:
o A PHP compiler for the .NET framework.
o Translates PHP code into Intermediate Language (IL) for execution on
the .NET platform.
o Provides interoperability with .NET components and libraries.
Here's a PHP program to find the length of the string "This is my first program":
<?php
$string = "This is my first program";
$length = strlen($string);
echo "Length of the string: " . $length;
?>
Q.8]. State the rules for declaring variables in PHP and write a PHP program
for a simple calculator. (AL Nov-2023)
<?php
// Declare variables
$num1 = 0;
$num2 = 0;
$result = 0;
$operator = "";
// Perform calculations
switch ($operator) {
case '+':
$result = $num1 + $num2;
break;
case '-':
$result = $num1 - $num2;
break;
case '*':
$result = $num1 * $num2;
break;
case '/':
if ($num2 != 0) {
$result = $num1 / $num2;
} else {
echo "Error: Division by zero!";
}
break;
default:
echo "Error: Invalid operator!";
}
}
// Display result
?>
<form method="post">
Number 1: <input type="number" name="num1" value="<?php echo $num1; ?>"><br>
Number 2: <input type="number" name="num2" value="<?php echo $num2; ?>"><br>
Operator:
<select name="operator">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select><br>
<input type="submit" value="Calculate">
</form>
<?php
echo "Result: " . $result;
?>
1. GET Method: Data ko URL mein dikhaya jata hai, aur iska upyog data prapt karne ke liye kiya jata
hai.
2. POST Method: Data ko URL mein nahin dikhaya jata, aur iska upyog data bhejne ke liye kiya jata
hai.
GET Method
- URL mein data dikhaya jata hai
- Data ki seema 2048 characters tak hoti hai
- Upyog: Search queries, pagination
POST Method
- URL mein data nahin dikhaya jata
- Data ki koi seema nahin hoti
- Upyog: Forms, registrations, logins
PHP SuperGlobals
- $_GET: GET data prapt karta hai
- $_POST: POST data prapt karta hai
- $_REQUEST: GET aur POST dono data prapt karta hai.
Q.11]. Differentiate between Session and Cookie. (CS Nov-2023) (CS June
2020)
Session:
Stored on the server.
Temporary and lasts until the browser is closed or the session expires.
Used for storing sensitive information.
Cookie:
Stored on the client's browser.
Can have an expiration date set by the server.
Used for storing less sensitive information.
Q.12]. Write a PHP script which takes the user’s name, password, and e-mail
values from the user and checks whether the user has filled the textboxes or not.
Also, check the e-mail field whether it is in the correct format or not. (AD 2022)
(CS June 2020)
Q.13]. Write about cookies and sessions in PHP with suitable program. (CS
Nov-2022)