Skip to content
AD-503 (A) · Internet and Web Technology/Quick Revision Short Notes

Internet and Web Technology (AD-503 (A)) - Unit 4 Short Notes

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

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Low weight</span>

Definition. <mark>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.</mark>

Key points.

  1. An XML document is built from tags, elements (<name>Ravi</name>) and attributes (id="5") nested under one root element.
  2. Its attributes (features) are extensibility, self-descriptiveness, platform independence, strict well-formedness and validation through DTD or Schema.
  3. 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

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>

Definition. XML stores data as a tree of elements; its uses are data exchange, configuration files, RSS feeds and web services.

Key points.

  1. A simple document has an optional prolog <?xml version="1.0"?>, one root element, child elements, attributes, text and comments <!-- -->.
  2. Rules: tags nest properly, are case-sensitive, and attribute values are quoted.
  3. Special characters use entities such as &lt; and &amp;.

DTD and Schemas

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Low weight</span>

Definition. <mark>A DTD or XML Schema (XSD) defines the legal structure of an XML document, so it can be validated.</mark> A DTD uses non-XML syntax, <!ELEMENT name (#PCDATA)>; XSD is written in XML and supports data types.

Key points.

  1. XSD data types are simple (text only, no children or attributes) or complex (elements with children or attributes).
  2. Built-in primitive types include xs:string, xs:boolean, xs:decimal, xs:float, xs:double, xs:date, xs:time and xs:dateTime.
  3. Derived types are built from primitives, for example xs:integer (from decimal), xs:int, xs:positiveInteger, xs:normalizedString and xs:token.
  4. Restrictions create user types: <xs:simpleType name="age"><xs:restriction base="xs:integer"><xs:maxInclusive value="100"/></xs:restriction></xs:simpleType>.
  5. 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

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>

Definition. Applications read XML through a parser and use it for data interchange between different systems.

Key points.

  1. A DOM parser loads the whole tree in memory; a SAX parser reads it event by event and uses less memory.
  2. XML is used in web services (SOAP), configuration files, RSS feeds and AJAX responses.
  3. In PHP, simplexml_load_file("a.xml") returns an object whose elements are read as properties.

Transforming XML using XSL and XSLT

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>

Definition. XSLT (Extensible Stylesheet Language Transformations) converts an XML document into HTML, text or other XML using a stylesheet of template rules.

Key points.

  1. An XSLT processor reads the XML source and the .xsl stylesheet and produces the result document.
  2. <xsl:template match="/"> selects nodes, <xsl:value-of select="name"/> prints a value and <xsl:for-each> loops.
  3. XPath expressions locate the nodes, and XSL-FO formats output for print.

PHP: Introduction and basic syntax of PHP

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Low weight</span>

Definition. <mark>PHP is an open-source, server-side scripting language embedded in HTML, written between <?php ... ?>.</mark> Variables start with $, statements end with ;.

Key points. PHP operators are:

  1. Arithmetic + - * / % **: $a % 3.
  2. Assignment = += -= *= .=: $x += 2.
  3. Comparison == === != !== < > <=>: $a === "5" also checks type.
  4. Logical && || ! and or xor: $a > 1 && $b < 5.
  5. String . concatenates: "Hi ".$n; array + unions and == compares arrays.
  6. 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

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Low weight</span>

Definition. <mark>Decision statements choose a path on a condition; looping statements repeat a block while a condition holds.</mark>

Key points.

  1. Decisions are if, if-else, elseif and switch, for example if ($m >= 40) echo "Pass"; else echo "Fail";.
  2. switch ($d) { case 1: echo "Mon"; break; default: echo "Other"; } compares one value with many cases.
  3. Loops are for ($i=1;$i<=5;$i++), while ($i<5) (test first), do { } while ($i<5); (runs at least once) and foreach ($arr as $k => $v) for arrays.
  4. break leaves a loop or switch; continue skips to the next iteration.

Asked: [7 marks] (Nov 2023) List and explain decision and looping concepts used in PHP.

PHP and HTML

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>

Definition. PHP code embedded in an HTML page runs on the server, and only its output reaches the browser.

Key points.

  1. The page is saved as .php, with HTML outside and PHP inside <?php ?>.
  2. <?= $x ?> is a short echo, and HTML can sit inside if and foreach blocks.
  3. A browser's view source shows no PHP.

Arrays

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>

Definition. A PHP array stores many values under one name as key-value pairs.

Key points.

  1. Indexed: $a = array(1,2,3); keys are 0, 1, 2.
  2. Associative: $m = ["ram"=>80]; keys are strings; multidimensional arrays nest arrays.
  3. Useful functions are count(), sort(), array_push(), array_pop() and foreach.

Functions

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>

Definition. A function is a named reusable block, declared with function name($p) { return ...; }.

Key points.

  1. Arguments pass by value by default; &$p passes by reference.
  2. Default values function f($x=5) and return give the result.
  3. Variables inside a function are local unless declared global.

Browser control and detection

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>

Definition. PHP reads the browser details the client sends and can control the response through headers.

Key points.

  1. $_SERVER['HTTP_USER_AGENT'] gives the browser name and version, and get_browser() decodes it.
  2. header("Location: b.php"); redirects, and it must be called before any output.
  3. Detection lets a page serve different content per browser.

String

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>

Definition. A string is a sequence of characters in single or double quotes; double quotes expand variables.

Key points.

  1. strlen(), strtoupper(), strrev(), str_replace(), substr() and strpos() are common functions.
  2. . joins strings.
  3. explode() splits a string into an array and implode() joins it back.

Form processing

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Low weight</span>

Definition. <mark>A PHP script reads submitted form data from $_POST or $_GET, validates it and responds.</mark>

Key points.

  1. empty() catches blank fields and filter_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

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>

Definition. PHP reads and writes files with fopen($f, mode), closed by fclose().

Key points.

  1. Modes are r read, w write (truncates), a append.
  2. fgets(), fread(), fwrite(), file_get_contents() and file_exists() are the main functions.
  3. feof() tests end of file.

Advance Features: Cookies and Sessions

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>

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.

  1. setcookie("u","Ravi",time()+3600); sets it and $_COOKIE["u"] reads it, before any output.
  2. session_start(); then $_SESSION["u"]="Ravi"; stores data, and session_destroy(); ends it.
  3. Sessions are more secure than cookies because data stays on the server.

Object Oriented Programming with PHP

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Low weight</span>

Definition. <mark>OOP models a program as objects, instances of a class that bundles properties and methods.</mark>

Key points.

  1. Concepts: class, object, encapsulation (private data), inheritance (extends), polymorphism (overriding) and reuse.
  2. __construct() initialises an object; $this refers 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-while runs at least once; break exits, continue skips.
  • Form data is in $_POST or $_GET; validate e-mail with filter_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.
Go to where you left off?

Quick Add to Notes

Save questions, your own notes and screenshots into notes filed by unit. It takes a free account.

Create free account

Have an account? Log in