How unit 4 is examined
XML basics, DTD and Schema, XSLT, then PHP (operators, control flow, forms, OOP); the asked topics are XML definition, schema data types, PHP operators, decision and looping, form validation and PHP OOP.
Introduction to XML
Low weight
Definition. XML (eXtensible Markup Language) is a W3C text-based markup language for storing and transporting data, in which the author defines his own self-describing tags.
Key points.
- An XML document is built from tags, elements (
<name>Ravi</name>) and attributes (id="5") nested under one root element. - Its attributes (features) are extensibility, self-descriptiveness, platform independence, strict well-formedness and validation through DTD or Schema.
- Unlike HTML, which displays data with fixed tags, XML describes data with user-defined tags and is case-sensitive, with every tag closed.
Asked: [7 marks] (Nov 2022) What is XML? What are the attributes of XML?
Uses of XML, simple XML, XML key components
Not asked since 2022
Definition. XML stores data as a tree of elements; its uses are data exchange, configuration files, RSS feeds and web services.
Key points.
- A simple document has an optional prolog
<?xml version="1.0"?>, one root element, child elements, attributes, text and comments<!-- -->. - Rules: tags nest properly, are case-sensitive, and attribute values are quoted.
- Special characters use entities such as
<and&.
DTD and Schemas
Low weight
Definition. A DTD or XML Schema (XSD) defines the legal structure of an XML document, so it can be validated. A DTD uses non-XML syntax, <!ELEMENT name (#PCDATA)>; XSD is written in XML and supports data types.
Key points.
- XSD data types are simple (text only, no children or attributes) or complex (elements with children or attributes).
- Built-in primitive types include
xs:string,xs:boolean,xs:decimal,xs:float,xs:double,xs:date,xs:timeandxs:dateTime. - Derived types are built from primitives, for example
xs:integer(from decimal),xs:int,xs:positiveInteger,xs:normalizedStringandxs:token. - Restrictions create user types:
<xs:simpleType name="age"><xs:restriction base="xs:integer"><xs:maxInclusive value="100"/></xs:restriction></xs:simpleType>. - A complex type example is
<xs:element name="p"><xs:complexType><xs:sequence><xs:element name="n" type="xs:string"/></xs:sequence></xs:complexType></xs:element>.
Asked: [7 marks] (Nov 2023) Explain the different data types in XML schema.
Using XML with application
Not asked since 2022
Definition. Applications read XML through a parser and use it for data interchange between different systems.
Key points.
- A DOM parser loads the whole tree in memory; a SAX parser reads it event by event and uses less memory.
- XML is used in web services (SOAP), configuration files, RSS feeds and AJAX responses.
- In PHP,
simplexml_load_file("a.xml")returns an object whose elements are read as properties.
Transforming XML using XSL and XSLT
Not asked since 2022
Definition. XSLT (Extensible Stylesheet Language Transformations) converts an XML document into HTML, text or other XML using a stylesheet of template rules.
Key points.
- An XSLT processor reads the XML source and the
.xslstylesheet and produces the result document. <xsl:template match="/">selects nodes,<xsl:value-of select="name"/>prints a value and<xsl:for-each>loops.- XPath expressions locate the nodes, and XSL-FO formats output for print.
PHP: Introduction and basic syntax of PHP
Low weight
Definition. PHP is an open-source, server-side scripting language embedded in HTML, written between <?php ... ?>. Variables start with $, statements end with ;.
Key points. PHP operators are:
- Arithmetic
+ - * / % **:$a % 3. - Assignment
= += -= *= .=:$x += 2. - Comparison
== === != !== < > <=>:$a === "5"also checks type. - Logical
&& || ! and or xor:$a > 1 && $b < 5. - String
.concatenates:"Hi ".$n; array+unions and==compares arrays. - Increment
++ --, and conditional?::$r = $m >= 40 ? "Pass" : "Fail";.
Asked: [7 marks] (Nov 2023) Describe the various operators supported by PHP.
Decision and looping with examples
Low weight
Definition. Decision statements choose a path on a condition; looping statements repeat a block while a condition holds.
Key points.
- Decisions are
if,if-else,elseifandswitch, for exampleif ($m >= 40) echo "Pass"; else echo "Fail";. switch ($d) { case 1: echo "Mon"; break; default: echo "Other"; }compares one value with many cases.- Loops are
for ($i=1;$i<=5;$i++),while ($i<5)(test first),do { } while ($i<5);(runs at least once) andforeach ($arr as $k => $v)for arrays. breakleaves a loop or switch;continueskips to the next iteration.
Asked: [7 marks] (Nov 2023) List and explain decision and looping concepts used in PHP.
PHP and HTML
Not asked since 2022
Definition. PHP code embedded in an HTML page runs on the server, and only its output reaches the browser.
Key points.
- The page is saved as
.php, with HTML outside and PHP inside<?php ?>. <?= $x ?>is a short echo, and HTML can sit insideifandforeachblocks.- A browser's
view sourceshows no PHP.
Arrays
Not asked since 2022
Definition. A PHP array stores many values under one name as key-value pairs.
Key points.
- Indexed:
$a = array(1,2,3);keys are 0, 1, 2. - Associative:
$m = ["ram"=>80];keys are strings; multidimensional arrays nest arrays. - Useful functions are
count(),sort(),array_push(),array_pop()andforeach.
Functions
Not asked since 2022
Definition. A function is a named reusable block, declared with function name($p) { return ...; }.
Key points.
- Arguments pass by value by default;
&$ppasses by reference. - Default values
function f($x=5)andreturngive the result. - Variables inside a function are local unless declared
global.
Browser control and detection
Not asked since 2022
Definition. PHP reads the browser details the client sends and can control the response through headers.
Key points.
$_SERVER['HTTP_USER_AGENT']gives the browser name and version, andget_browser()decodes it.header("Location: b.php");redirects, and it must be called before any output.- Detection lets a page serve different content per browser.
String
Not asked since 2022
Definition. A string is a sequence of characters in single or double quotes; double quotes expand variables.
Key points.
strlen(),strtoupper(),strrev(),str_replace(),substr()andstrpos()are common functions..joins strings.explode()splits a string into an array andimplode()joins it back.
Form processing
Low weight
Definition. A PHP script reads submitted form data from $_POST or $_GET, validates it and responds.
Key points.
empty()catches blank fields andfilter_var($e, FILTER_VALIDATE_EMAIL)checks the e-mail format.
<form method="post">
User <input name="u"> Pass <input type="password" name="p"> Email <input name="e"><input type="submit"></form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["u"]) || empty($_POST["p"]) || empty($_POST["e"])) echo "Fill all fields";
elseif (!filter_var($_POST["e"], FILTER_VALIDATE_EMAIL)) echo "Invalid e-mail";
else echo "Welcome " . htmlspecialchars($_POST["u"]);
}
?>
Asked: [7 marks] (Nov 2022) Write a PHP script which takes the user name, password and e-mail values from user and checks whether the user has filled the textboxes or not. Also, check the e-mail field whether it is incorrect format or not.
Files
Not asked since 2022
Definition. PHP reads and writes files with fopen($f, mode), closed by fclose().
Key points.
- Modes are
rread,wwrite (truncates),aappend. fgets(),fread(),fwrite(),file_get_contents()andfile_exists()are the main functions.feof()tests end of file.
Advance Features: Cookies and Sessions
Not asked since 2022
Definition. A cookie is a small data item stored in the browser; a session keeps user data on the server against a session id.
Key points.
setcookie("u","Ravi",time()+3600);sets it and$_COOKIE["u"]reads it, before any output.session_start();then$_SESSION["u"]="Ravi";stores data, andsession_destroy();ends it.- Sessions are more secure than cookies because data stays on the server.
Object Oriented Programming with PHP
Low weight
Definition. OOP models a program as objects, instances of a class that bundles properties and methods.
Key points.
- Concepts: class, object, encapsulation (
privatedata), inheritance (extends), polymorphism (overriding) and reuse. __construct()initialises an object;$thisrefers to it; objects use->.
class A { private $n; function __construct($n){ $this->n=$n; } function hi(){ return "Hi ".$this->n; } }
class B extends A { function hi(){ return "Hello ".parent::hi(); } }
$o = new B("Ravi"); echo $o->hi(); // Hello Hi Ravi
Asked: [7 marks] (Nov 2022) Explain the concept of object oriented programming with PHP.
Last-minute revision
- XML is a W3C markup language with user-defined, case-sensitive tags and one root element.
- Well-formed means correct syntax; valid means it also matches its DTD or XSD.
- XSD is written in XML and has data types; a DTD is not and has none.
- XSD types: simple, complex, primitive (string, decimal, date) and derived (integer, token).
- XSLT turns XML into HTML using templates and XPath.
- PHP is server-side; variables start with
$;.concatenates strings. <mark>compares value,</mark>=compares value and type.do-whileruns at least once;breakexits,continueskips.- Form data is in
$_POSTor$_GET; validate e-mail withfilter_var. - Cookies live in the browser; sessions live on the server.
- OOP in PHP:
class,new,__construct,extends,->.
Memory hooks
- XML tags: Extensible, Self-describing, Strict.
- DOM = whole tree in memory; SAX = streaming events.
- Cookie is client, Session is server.
- Loops: FWDF = for, while, do-while, foreach.
Coverage checklist
- Introduction to XML: Nov 2022 definition and attributes.
- uses of XML, simple XML, XML key components: covered, no past questions.
- DTD and Schemas: Nov 2023 schema data types.
- Using XML with application: covered, no past questions.
- Transforming XML using XSL and XSLT: covered, no past questions.
- PHP: Introduction and basic syntax of PHP: Nov 2023 operators.
- decision and looping with examples: Nov 2023 decision and looping.
- PHP and HTML: covered, no past questions.
- Arrays: covered, no past questions.
- Functions: covered, no past questions.
- Browser control and detection: covered, no past questions.
- string: covered, no past questions.
- Form processing: Nov 2022 PHP validation script.
- Files: covered, no past questions.
- Advance Features: Cookies and Sessions: covered, no past questions.
- Object Oriented Programming with PHP: Nov 2022 OOP.