How unit 4 is examined
XML basics, DTD versus Schema, XSLT, then PHP: control structures, forms (GET/POST), cookies versus sessions and OOP carry the marks.
Introduction to XML
Medium weight
Definition. XML (eXtensible Markup Language) is a W3C markup language for describing, storing and transporting data, in which the author defines his own tags.
Key points.
- XML describes what the data is, while HTML describes how data is displayed.
- XML tags are user-defined and extensible; HTML tags are predefined.
- XML is case-sensitive and strict: every tag must be closed and properly nested, while HTML tolerates errors.
- An XML document has a prolog (
<?xml version="1.0"?>), exactly one root element, nested child elements and optional attributes. - XML is platform-independent plain text, so different systems can exchange it.
| Basis | HTML | XML |
|---|---|---|
| Purpose | Displays data | Describes and carries data |
| Tags | Predefined | User-defined |
| Case | Not case-sensitive | Case-sensitive |
| Closing tags | Optional for some (<br>) |
Mandatory for all |
| Errors | Browser ignores them | Parser stops (must be well-formed) |
| Root | Fixed <html> |
Any single root |
| Attribute quotes | Optional | Mandatory |
Answer frame. Open with the definition; draw the comparison table; add one XML snippet showing prolog, root and nesting; close with "XML carries data, HTML presents it".
Asked: [7 marks] (Nov 2019, Jun 2025) Differentiate HTML and XML. What is XML and how does it differ from HTML? Describe the basic structure of an XML document.
Uses of XML
Low weight
Definition. XML is used for platform-independent storage and exchange of structured data.
Key points.
- Extensibility: authors invent tags that fit their data, so one format serves books, orders or feeds.
- Readability: it is plain text that humans and programs can both read.
- Validation: a DTD or Schema checks the structure before use.
- Interoperability: different platforms and languages exchange data through it, as in RSS feeds, SOAP web services and configuration files.
- Data is separate from presentation, so XSLT can render one file in many forms.
Asked: [7 marks] (Jun 2025) Discuss the advantages of using XML for data storage and exchange in web applications.
Simple XML
Not asked since 2022
Definition. A simple XML document is a well-formed document: prolog, one root element, nested elements.
Key points.
- Every start tag has a matching end tag, or is self-closed like
<a/>. - Elements nest properly and there is one root.
- Attribute values are quoted; names are case-sensitive.
- Comments are written
<!-- ... -->.
<?xml version="1.0"?>
<student><name>Ravi</name><roll>101</roll></student>
XML keycomponents
High weight
Definition. An XML document is built from a prolog, elements, attributes, text, comments, entities and a root element; it is well-formed when it obeys the syntax rules.
Key points.
- Prolog: the declaration
<?xml version="1.0" encoding="UTF-8"?>states the version and encoding. - Element: a start tag, content and end tag, such as
<name>Ravi</name>; elements nest to form a tree. - Root element: exactly one element contains all others.
- Attribute: a name="value" pair inside the start tag giving extra information about the element, such as
<book id="5">; the value must be quoted and the name unique within the element. - Text (PCDATA) is the character data inside an element; CDATA sections hold text that the parser must not interpret.
- Entities: predefined references such as
< > & " 'stand for reserved characters. - Comments and processing instructions:
<!-- -->for notes. - Well-formed rules: one root, proper nesting, closed tags, quoted attributes, case-sensitive names.
- Valid: well-formed and also conforming to a DTD or Schema.
Example.
<?xml version="1.0"?>
<library>
<book id="5"><title>PHP</title></book>
</library>
Answer frame. Open with the XML definition; then list components 1-7 with the example above; state attributes with the id example; close with well-formed versus valid, and mention the HTML difference in one line.
Asked: [7 marks] (Dec 2020) What is XML? What are the attributes of XML? Asked: [14 marks] (Dec 2024) Write a short note: XML Key Components (with OOP in PHP, MySQL and Need for CSS).
DTD andSchemas
High weight
Definition. A DTD (Document Type Definition) is a grammar that defines the legal elements, attributes and entities of an XML document, so that the document can be validated.
Key points.
- Purpose: a DTD checks the structure of an XML file; a document that obeys it is valid.
- Element declaration:
<!ELEMENT name (content)>; content can be#PCDATA,EMPTY,ANYor a child list, with+one or more,*zero or more,?optional,,sequence and|choice. - Attribute declaration:
<!ATTLIST book id CDATA #REQUIRED>; types are CDATA, ID, enumerated; defaults are#REQUIRED,#IMPLIED,#FIXED. - Entity declaration:
<!ENTITY co "RGPV">defines a reusable text; used as&co;. - Internal DTD sits inside the XML file in
<!DOCTYPE root [ ... ]>. - External DTD is a separate
.dtdfile, linked by<!DOCTYPE root SYSTEM "file.dtd">orPUBLIC "id" "url", and can be shared by many documents. - Both together: the DOCTYPE names an external file and also holds an internal subset in
[ ]; the internal declarations are read first and override the external ones. - XML Schema (XSD) is the XML-based, richer alternative to a DTD.
Example (internal plus external).
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "note.dtd" [
<!ELEMENT note (to,body)>
<!ATTLIST note id CDATA #REQUIRED>
]>
<note id="1"><to>Ravi</to><body>Hi</body></note>
| Basis | DTD | XML Schema (XSD) |
|---|---|---|
| Syntax | Own non-XML syntax | Written in XML |
| Data types | Only text (PCDATA, CDATA) | Rich types: string, integer, date, boolean |
| Namespaces | Not supported | Supported |
| Extensibility | Limited, cannot extend types | Types can be extended and reused |
| Occurrence control | Only ? * + |
Exact minOccurs/maxOccurs |
| Parsing | Needs a separate parser | Same XML parser and tools |
Answer frame. DTD question: define, give purpose, components (element, attribute, entity), internal versus external, then the example; close with "the DTD validates structure". Both-DTDs question: draw the example above and explain the DOCTYPE line. Comparison: table above plus one XSD snippet, <xs:element name="age" type="xs:integer"/>.
Asked: [7 marks] (Nov 2019, Dec 2020, Dec 2024) Explain the term DTD in detail. What is DTD? Why do we use it? What are its applications? Asked: [7 marks] (Jun 2020) Explain the different components of DTD with example. Asked: [7 marks] (Nov 2023) Compare the critical differences between DTD and XML Schema. Asked: [7 marks] (Dec 2024) How can both Internal and External DTDs be used in an XML file? Show with an example. Asked: [7 marks] (Dec 2025) Explain XML components, DTD and XML schemas.
Using XML with applications
Not asked since 2022
Definition. An XML parser reads an XML file and gives an application access to its data.
Key points.
- DOM parser loads the whole file as a tree in memory, allowing random access and change.
- SAX parser is event-based and streams the file, using little memory but only forward reading.
- PHP reads XML with
simplexml_load_file("a.xml")or the DOM classes. - Applications use XML for config files, feeds and web services.
Transforming XML using XSL and XSLT
Medium weight
Definition. XSL is the stylesheet language for XML, and XSLT (XSL Transformations) converts an XML document into another format such as HTML, using template rules.
Key points.
- XSLT is itself written in XML, and the stylesheet root is
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">. <xsl:template match="/">defines a rule applied to the node matched by an XPath expression;/is the root.<xsl:value-of select="name"/>writes the value of a node.<xsl:for-each select="students/student">loops over repeated nodes.<xsl:if>and<xsl:choose>give conditions, and<xsl:sort>orders output.- The XML file links the stylesheet with
<?xml-stylesheet type="text/xsl" href="s.xsl"?>, and the processor produces the output tree. - Its use is to present the same XML data as HTML for browsers.
Example. s.xml: <students><student><name>Ravi</name></student></students>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html><body>
<xsl:for-each select="students/student">
<p><xsl:value-of select="name"/></p>
</xsl:for-each>
</body></html>
</xsl:template>
</xsl:stylesheet>
Output: <html><body><p>Ravi</p></body></html>
Answer frame. Open by defining XSL and XSLT; show the XML, the stylesheet and the output; explain the template, value-of and for-each lines; close with "XSLT separates data from presentation".
Asked: [7 marks] (Nov 2023, Dec 2025) Briefly explain XSL transformation with an example of script. Explain transformation of XML using XSL/XSLT.
PHP introduction and basic syntax
Low weight
Definition. PHP (Hypertext Preprocessor) is an open-source, server-side scripting language embedded in HTML.
Key points.
- PHP code sits between
<?phpand?>and every statement ends with a semicolon; files use.php. - Variables start with
$, need no type declaration and are case-sensitive; comments use//,#and/* */. echoandprintoutput text; operators are arithmetic, comparison, logical, assignment and string (.).- Types are integer, float, string, boolean, array, object and NULL.
- The server runs the script and sends only the HTML result to the browser.
<?php $n = "RGPV"; echo "Hello " . $n; // Hello RGPV ?>
Asked: [7 marks] (Dec 2025) Explain PHP syntax, arrays, functions and form processing.
Decision and looping
Low weight
Definition. Control structures decide which statements run (decision) or repeat them (loops).
Key points.
- Decision:
if,if...else,elseifandswitchwithcase,break,default. - Loops:
for(known count),while(test first),do...while(runs at least once) andforeach(arrays). breakleaves a loop andcontinueskips one iteration.- Example below shows if and for.
<?php
$m = 55;
if ($m >= 40) { echo "Pass"; } else { echo "Fail"; } // Pass
for ($i = 1; $i <= 3; $i++) { echo $i; } // 123
foreach (["a", "b"] as $v) { echo $v; } // ab
?>
Asked: [7 marks] (Nov 2022) Explain about the control structures in PHP with illustrations.
PHP and HTML
Not asked since 2022
Definition. PHP is embedded in HTML so the page mixes static markup with generated content.
Key points.
- Switch between them with
<?php ... ?>, and<?= $x ?>is a shortcut for echo. - Output from
echomay contain HTML tags. - The server executes the PHP first; the browser never sees the PHP code.
- Loops can wrap HTML to build tables.
Arrays
Not asked since 2022
Definition. An array stores many values under one variable name.
Key points.
- Indexed:
$a = array(10, 20);accessed by number,$a[0]. - Associative:
$p = ["name" => "Ravi"];accessed by key. - Multidimensional: an array of arrays,
$m[1][0]. - Useful functions:
count(),sort(),array_push(),in_array().
Functions
Not asked since 2022
Definition. A function is a named, reusable block of code.
Key points.
- User-defined:
function add($a, $b) { return $a + $b; }called asadd(2, 3). - Built-in functions include
strlen(),count()anddate(). - Arguments may have defaults,
function f($x = 5), and can be passed by reference with&. - Variables inside a function are local unless declared
global.
Browser control and detection
Not asked since 2022
Definition. PHP detects the visitor's browser from the HTTP header and can control it by sending headers.
Key points.
$_SERVER['HTTP_USER_AGENT']holds the browser and OS name.get_browser()decodes it into details.header("Location: page.php");redirects the browser and must run before any output.- Detection lets the page serve content suited to the browser.
String
Not asked since 2022
Definition. A string is a sequence of characters in single or double quotes.
Key points.
- Double quotes expand variables, single quotes do not;
.joins strings. - Common functions:
strlen(),strrev(),strtoupper(),strpos(),substr(),str_replace(). explode()splits a string into an array andimplode()joins an array.trim()removes surrounding spaces.
Form processing
Medium weight
Definition. Form processing is collecting user input from an HTML form and handling it in a PHP script through the $_GET or $_POST superglobals.
Key points.
- The form's
methodattribute chooses GET or POST andactionnames the script. - GET appends data to the URL as
?name=Ravi, so it is visible, bookmarkable and limited in length (about 2000 characters). - POST sends data in the request body, so it is hidden and has no practical size limit.
- Use GET for searches and POST for passwords and uploads.
isset()andempty()test for missing input, andfilter_var($e, FILTER_VALIDATE_EMAIL)checks the email format.
| Basis | GET | POST |
|---|---|---|
| Data location | URL query string | Request body |
| Visibility | Visible | Hidden |
| Length | Limited | Practically unlimited |
| Security | Weak | Better |
| Bookmark/cache | Yes | No |
| PHP array | $_GET |
$_POST |
Example (validation script).
<form method="post">
User <input name="u"> Pass <input name="p" type="password"> 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 email";
else echo "Welcome " . htmlspecialchars($_POST["u"]);
}
?>
Answer frame. GET/POST question: define form handling, table above, one short form with $_GET and $_POST; close with when to use each. Script question: draw the form, then the empty check, then the email check, then the success message.
Pitfall: Sending a password with GET exposes it in the URL and browser history.
Asked: [7 marks] (Jun 2020) Write a PHP script which takes the user name, password and email values and checks whether the textboxes are filled and whether the email format is correct. Asked: [7 marks] (Nov 2022, Nov 2023) State the differences between GET and POST methods. Explain form handling with the get and post methods in PHP.
Files
Not asked since 2022
Definition. PHP reads, writes and uploads files on the server.
Key points.
fopen("a.txt", "r")opens a file; modes arer,w,a; close withfclose().fread(),fgets()read andfwrite()writes;file_exists()andunlink()check and delete.- Uploads use a form with
enctype="multipart/form-data", read from$_FILESand saved withmove_uploaded_file().
Advance features: cookies and sessions
High weight
Definition. A cookie is a small text file stored in the client's browser, and a session stores user data on the server, identified by a session ID; both let stateless HTTP remember a user.
Key points.
- Set a cookie with
setcookie(name, value, expire, path)before any output, for examplesetcookie("user", "Ravi", time()+3600);. - Read it through
$_COOKIE["user"]; delete it by setting the expiry in the past. - A cookie lives until its expiry time, so it can persist after the browser closes.
session_start()begins a session and must be the first call on each page; data goes in$_SESSION["user"] = "Ravi";.- The server keeps the data and sends only a session ID (PHPSESSID cookie) to the browser.
session_destroy()ends the session andunset($_SESSION["user"])removes one value.- Session lifecycle: start, store, read on later pages, destroy at logout or timeout.
- Cookies suit preferences and "remember me", sessions suit login and shopping carts.
| Basis | Cookie | Session |
|---|---|---|
| Storage | Client browser | Server |
| Security | Less, user can edit it | More, only the ID is at the client |
| Lifetime | Until expiry date | Until browser closes or logout |
| Capacity | About 4 KB each | Large, server limited |
| Function | setcookie() |
session_start() |
| Array | $_COOKIE |
$_SESSION |
Example.
<?php
setcookie("user", "Ravi", time() + 3600);
session_start();
$_SESSION["role"] = "admin";
echo $_COOKIE["user"] ?? "new", $_SESSION["role"];
?>
Answer frame. Comparison: open with both definitions, table above, close with an example. Program question: define each, list the functions, then the program above with a second page reading $_SESSION.
Pitfall:
setcookie()andsession_start()after any HTML output cause a "headers already sent" error.
Asked: [7 marks] (Jun 2020, Nov 2023) Differentiate between Session and Cookie. What is the difference between sessions and cookies in PHP? Asked: [7 marks] (Nov 2022) Write about cookies and sessions in PHP with suitable program. Asked: [7 marks] (Dec 2025) Explain cookies, sessions and OOP concepts in PHP. Asked: [14 marks] (Dec 2024) Explain: i) Cookies and sessions ii) Creating Database iii) Planning and Publishing Websites (the last two belong to Units 5 and 1).
Object oriented programming with PHP
Medium weight
Definition. Object oriented programming organises code into classes and objects that combine data (properties) and behaviour (methods).
Key points.
- Class is the blueprint declared with
class; an object is an instance made withnew. - Properties and methods are reached with
->, and$thisrefers to the current object. - The constructor
__construct()runs automatically when an object is created. - Encapsulation hides data using
public,protectedandprivatevisibility. - Inheritance: a child class takes the parent's properties and methods using
extends, and adds its own. - Polymorphism: a child overrides a parent method, so the same call behaves differently; interfaces (
implements) also give this. - Advantages: reuse, easy maintenance and modular web applications.
Example.
<?php
class Animal { function speak() { return "..."; } }
class Dog extends Animal { function speak() { return "Bark"; } }
$d = new Dog();
echo $d->speak(); // Bark
?>
Answer frame. OOP question: define class, object, then points 4-6 with the example; close with advantages. Inheritance question: define inheritance, draw the tree, show extends, state types (single, multilevel, hierarchical), close with reuse.
Asked: [7 marks] (Jun 2020, Jun 2025) Explain the concept of object oriented programming with PHP, including encapsulation, inheritance and polymorphism. Asked: [7 marks] (Nov 2019) Explain about inheritance with suitable diagram.
Last-minute revision
- XML is case-sensitive, has one root, and every tag must close.
- HTML displays data; XML describes data; XML tags are user-defined.
- DTD:
<!ELEMENT>,<!ATTLIST>,<!ENTITY>; internal uses[ ], external usesSYSTEM "x.dtd". - XSD is written in XML and has data types and namespaces; DTD has neither.
- XSLT elements: template, value-of, for-each, if, choose, sort.
- PHP tags are
<?php ... ?>, variables start with$, statements end with;. - GET is in the URL and limited; POST is in the body and safer.
- Cookie on client with
setcookie(), session on server withsession_start(). - Cookie is about 4 KB; call both before any output.
- OOP:
class,new,extends,__construct, visibility public/protected/private.
Memory hooks
- DTD grammar: E-A-E, Element, Attlist, Entity.
- GET = Glass window (visible), POST = Post box (hidden).
- Cookie crumbs stay with the client; the session ticket is held by the server.
- Inheritance: child
extendsparent.
Coverage checklist
- Introduction to XML: HTML vs XML (Nov 2019, Jun 2025).
- uses of XML: advantages of XML (Jun 2025).
- simple XML: well-formed structure.
- XML keycomponents: what is XML, attributes (Dec 2020); short note (Dec 2024).
- DTD andSchemas: DTD, components, DTD vs Schema, internal and external, XML components (Nov 2019 to Dec 2025).
- Using XML with application: DOM and SAX parsers.
- Transforming XML using XSL and XSLT: XSLT example (Nov 2023, Dec 2025).
- PHP: Introduction and basic syntax of PHP: PHP syntax (Dec 2025).
- decision and looping with examples: control structures (Nov 2022).
- PHP and HTML: embedding.
- Arrays: indexed, associative, multidimensional.
- Functions: user-defined and built-in.
- Browser control and detection: user agent, header.
- string: string functions.
- Form processing: GET vs POST, validation script (Jun 2020, Nov 2022, Nov 2023).
- Files: fopen, uploads.
- Advance Features: Cookies and Sessions: comparison, program, short note (Jun 2020 to Dec 2025).
- Object Oriented Programming with PHP: OOP, inheritance (Nov 2019, Jun 2020, Jun 2025).