0% found this document useful (0 votes)
8 views14 pages

Unit-4 Introduction to XML

Notes Internet and Web Technology
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
8 views14 pages

Unit-4 Introduction to XML

Notes Internet and Web Technology
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 14

UNIT IV:XML: Introduction to XML, uses of XML, simple XML, XML key components,

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.

UNIT IV: XML and PHP


1. What is XML schema? State its purpose and its advantages over DTD. (AL Nov-2023)
2. What is XML? What are the attributes of XML? (CY May-2023) (AD 2022) (CS 2020)
3. Explain the different components of DTD with example. (CS 2020)
4. Compare the critical differences between DTD and XML. (CS Nov-2023)
5. Briefly explain XSL transformation with an example of script. (CS Nov-2023)
6. Introduction and basic syntax of PHP, decision and looping with examples, PHP and
HTML, Arrays, Functions, Browser control and detection, string, Form processing,
Files. (General topic coverage)
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)
8. State the rules for declaring variables in PHP and write a PHP program for a simple
calculator. (AL Nov-2023)
9. Explain database connectivity in PHP with reference to MySQL. (AL Nov-2023)
10. Explain form handling with the get and post methods in PHP. (CS Nov-2023)
11. Differentiate between Session and Cookie. (CS Nov-2023) (CS June 2020)
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)
13. Write about cookies and sessions in PHP with suitable program. (CS Nov-2022)
14. Explain Loop Statements in PHP. (CY May-2023)
UNIT IV: XML and PHP
1. XSLT (CS Nov-2023)
UNIT IV:XML: Introduction to XML, uses of XML, simple XML, XML key components,
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 (Extensible Markup Language)


1. Introduction to XML: XML is a markup language used for storing and transporting
language used for storing and transporting data between systems. It’s platform -
independent, language, independent, and self-descriptive.
2. Use of XML: XML is used in various applications, such as:
a. Data Exchange between Systems
b. Configuration files
c. Web services
d. RSS feeds
e. Document Publishing
3. Simple XML: Basic XML syntax includes:
Elements(tags)
Attributes (name-value-pairs)
Entities (Character references)
Namespaces (unique identifiers)
Document Type Definitions (DTD)

XML Example

<bookstore>
<book>
<title>Learning XML</title>
<author>John Doe</author>
</book>
</bookstore>

4. XML kye Components:


a. Elements: Building block of XML documents. Represented by tags(< >) and
contain attributes and contents.
b. Attributes: Provide additional information about elements.
c. Namespace: Unique identifiers to elements and attributes.
d. Comments: Note within the XML code, <-- This is a comment -->
e. XML Declaration: Indicates the XML version, <? Xml version=”1.0”?>.
f. Processing Instructions: Instructions for applications processing the XML.
g.
5. DTD (Document Type Definition) and Schemas: These defines the structure and
allowable content for XML documents. DTD are older and simpler. While XML
schemas (XSD) are more powerful and can specific data types and constraints.
6. Using XML with application : XML can be integrated with various applications for
storing and exchanging data. For example, many databases can export and import data
as XML.
7. Transferring XML using XSL and XSLT: XSL (extensible SyleSheet Language)
and XSLT(XSL Transformations) are used to transform XML data into other formats
like HTML, plain text, or another XML document. Example XSL code might

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

UNIT IV: XML and PHP

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:

 Well-Formed: Follows syntactical rules.


 Self-Descriptive: Tags are custom-defined and descriptive.
 Hierarchical: Data is organized in a tree-like structure.
 Extensible: Users can create their own tags as needed.

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:

 Element Declarations: Define elements, e.g., <!ELEMENT note (to, from,


heading, body)>.
 Attribute Declarations: Define attributes, e.g., <!ATTLIST note date CDATA
#REQUIRED>.
 Entity Declarations: Define reusable entities, e.g., <!ENTITY writer "John Doe">.

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

DTD (Document Type


Aspect XML Schema
Definition)

Syntax Non-XML syntax XML syntax

Limited (e.g., CDATA, ID, Wide range of built-in and custom


Data Types
IDREF) types

Namespace Support Does not support Fully supports namespaces

Less flexible, harder to Highly extensible, supports


Extensibility
extend complex structures

Advanced validation (e.g.,


Validation Capabilities Basic validation
min/max values, patterns)

Complexity Handling Simpler More complex

Inheritance and
Not supported Supported
Polymorphism

Less interoperable with Highly interoperable with XML


Interoperability
modern tools tools

Documentation Limited Allows for internal documentation

Limited support from Widely supported by XML


Tool Support
modern tools development tools

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)

1. Transforms XML documents into other formats (HTML, text, XML)


2. Uses stylesheets to define transformation rules
3. Supports templating, looping, and conditional statements
Example

Input (books.xml): XML document


Stylesheet (books.xsl): XSLT transformation rules
Output: HTML document displaying book list

Key Benefits

1. Flexible data transformation


PHP Basics
2. Platform-independent 1. Server-side scripting
3. Extensive support for XML standard language
2. Used for web
Q.6]. Introduction and basic syntax of PHP, decision development
3. Open-source, platform-
and looping with examples, PHP and HTML, Arrays,
independent
Functions, Browser control and detection, string,
Form processing, Files. (General topic coverage) Syntax
Introduction 1. <?php ?> tags
2. Variables:
1. PHP (Hypertext Preprocessor) is a server-side scripting language. $variable_name
2. Used for web development, especially for dynamic websites. 3. Data types: strings,
3. Open-source, platform-independent. integers, booleans, arrays,
objects
Basic Syntax
Control Structures
1. PHP code starts with <?php and ends with?>. 1. Conditional statements:
2. Variables: $variable_name = value; if, else, switch
3. Data types: strings, integers, floats, booleans, arrays, objects. 2. Loops: for, while, do-
4. Operators: arithmetic, comparison, logical. while

Decision and Looping Key Features


1. Arrays
1. Conditional statements: 2. Functions
1. if statement: if (condition) {code} 3. Form processing
2. else statement: if (condition) {code} else {code} 4. File operations
3. switch statement: switch (variable) {case value: code; break;} 5. Browser detection
2. Loops:
1. for loop: for ($i = 0; $i < 10; $i++) {code} Example Code
2. while loop: while (condition) {code} <?php
3. do-while loop: do {code} while (condition); $name = 'John Doe';
if ($name == 'John Doe') {
PHP and HTML echo 'Hello, John!';
}
1. Embed PHP code in HTML using <?php ?> tags. ?>
2. Use echo statement to output HTML.

Arrays

1. Indexed arrays: $array = array('value1', 'value2');


2. Associative arrays: $array = array('key1' => 'value1', 'key2' => 'value2');
3. Multidimensional arrays.

Functions

1. User-defined functions: function name($parameter) { code }


2. Built-in functions: strlen(), substr(), array_push(), etc.

Browser Control and Detection

1. $_SERVER superglobal array: $_SERVER['HTTP_USER_AGENT']


2. Browser detection using getget_browser() function.

Strings

1. String functions: strlen(), substr(), str_replace(), etc.


2. String concatenation: $string1 . $string2

Form Processing

1. $_POST and $_GET superglobal arrays.


2. Form validation using PHP.

Files

1. File upload: $_FILES superglobal array.


2. File operations: fopen(), fclose(), fread(), etc.

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.

PHP Program to Find the Length of a String

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)

Rules for Declaring Variables in PHP

1. Variable names start with a dollar sign ($).


2. Variable names can contain letters (a-z, A-Z), numbers (0-9), and underscores (_).
3. Variable names cannot start with numbers.
4. Variable names are case-sensitive.
5. Variables must be declared before use.
6. Variables can hold different data types (e.g., integer, string, float, boolean).
7. Variables can be reassigned.

Data Types in PHP


1. Integer: whole numbers (e.g., 1, 2, 3).
2. String: text (e.g., "hello", 'hello').
3. Float: decimal numbers (e.g., 3.14, -0.5).
4. Boolean: true or false.
5. Array: collection of values.
6. Object: instance of a class.

Simple Calculator Program in PHP

<?php
// Declare variables
$num1 = 0;
$num2 = 0;
$result = 0;
$operator = "";

// Get user input


if ($_POST) {
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
$operator = $_POST['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;
?>

Q.9]. Explain database connectivity in PHP with reference to MySQL. (AL


Nov-2023)
Database Connectivity in PHP with MySQL
To connect and interact with a MySQL database using PHP, follow these steps:
1. Connecting to the Database:
o Use the mysqli or PDO (PHP Data Objects) extension to connect to the
database.
o Provide connection details such as the hostname, username, password, and
database name.
2. Executing SQL Queries:
o Use the connection object to execute SQL queries like SELECT, INSERT,
UPDATE, and DELETE.
3. Fetching Data:
o Retrieve query results and process them in PHP.
4. Closing the Connection:
o Close the database connection to free up resources.
Example: Using mysqli
Here’s a step-by-step example of connecting to a MySQL database using the mysqli
Q.10]. Explain form handling with the get and post methods in PHP. (CS Nov-
2023)

Form Handling in PHP

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.

Aspect Session Cookie


Storage Location Server Client's browser
Lifetime Temporary Can be persistent
Security More secure Less secure
Capacity Larger amounts of data Limited to about 4KB
Accessibility Server-side only Client and server
Use Cases Sensitive information Less sensitive information
Browser Settings Not dependent Can be disabled
Aspect Session Cookie
Browser Support Widely Supported Widely Supported
Implementation Server-side coding Simple
Data Consistency Consistent during session Might get altered
Privacy Higher privacy Lower privacy
Complexity More Complex Simpler
User Experience Personalized Tracking Perference

‘These are the main points

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)

Q.14]. Explain Loop Statements in PHP. (CY May-2023)

Q.15]. UNIT IV: XML and PHP


2. XSLT (CS Nov-2023)

You might also like