CSIT128 Week 10 Revision, Solution
CSIT128 Week 10 Revision, Solution
Q1.
Given the following XML file student.xml
<?xml version="1.0" encoding="UTF-8"?>
<studentList>
<student>
<firstName>John</firstName>
<lastName>Smith</lastName>
<email>jsmith@gmail.com</email>
<mobile>0211223344</mobile>
<points> 100 </points>
<address> DXB</address>
</student>
<student>
<firstName>Jiiii</firstName>
<lastName>Sdgfdgfd</lastName>
<email>jsmith@gmail.com</email>
<mobile>0211223344</mobile>
<points> 100 </points>
<address> DXB</address>
</student>
</studentList>
Answer
<!DOCTYPE studentList [
<!ELEMENT studentList(student*)
<!ELEMENT student (firstName, lastName, email, mobile, points, address)>
<!ELEMENT firstName (#PCDATA)>
<!ELEMENT lastName (#PCDATA)>
<!ELEMENT email (#PCDATA)>
<!ELEMENT mobile (#PCDATA)>
<!ELEMENT points (#PCDATA)>
<!ELEMENT address (#PCDATA)>
]>
Q2
Question 1 (10 marks): XML and DTD
Given the following DTD file student.dtd
<?xml version="1.0" encoding="UTF-8" ?>
<?xsl-stylesheet type=”text/xsl” href=”menu.xsl”?>
<!DOCTYPE menu[
<!ELEMENT menu (foodItems+,milkshakes+)>
<!ELEMENT fooditems (name, cost ,calories ,description)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT cost (#PCDATA)>
<!ELEMENT calories (#PCDATA)>
<!ELEMENT description (#PCDATA)>
<!ELEMENT milkshakes (name, cost, calories, description)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT cost (#PCDATA)>
<!ELEMENT calories (#PCDATA)>
<!ELEMENT description (#PCDATA)>
<!ATTLIST foodItems idNumber CDATA #REQUIRED>
<!ATTLIST milkshakes milkType CDATA #REQUIRED>
<!ENTITY a "Add">
<!ENTITY u "Update">
<!ENTITY d "Delete">
]>
Write an XML document which conforms to the above DTD file.
Answer
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE menu SYSTEM "student.dtd">
<menu>
<foodItems idNumber="1">
<name>French Fries</name>
<cost>13 dhs </cost>
<calories>120</calories>
<description> Crispy golden potato sticks.</ description>
</foodItems>
<foodItems idNumber="2">
<name>Hot dog</name>
<cost>10 dhs</cost>
<calories>215</calories>
<description> Grilled sausages in soft buns, topped with various
condiments.</description>
</foodItems>
<milkshakes milkType="Cow’s Milk">
<name> Classic Vanilla Milkshake</name>
<cost>20 dhs</cost>
<calories>260</calories>
<description>Rich and creamy vanilla milkshake.</description>
</milkshakes>
<milkshakes milkType="Almond Milk">
<name> Banana Almond Shake</name>
<cost>213</cost>
<calories>400</calories>
<description>Refreshing banana almond milkshake.</description>
</milkshakes>
</menu>
Answer
<!DOCTYPE html>
<html>
<head>
<title>Buttons</title>
<style>
button {
font-size: 20px;
margin: 10px;
padding: 10px;
}
</style>
</head>
<body>
<h2>Number:</h2>
<h3 id="number">5</h3>
<button onclick="increase()">+</button>
<button onclick="decrease()">-</button>
<script>
let x = 5;
function increase() {
x += 5;
updateNumber();
}
function decrease() {
x -= 5;
updateNumber();
}
function updateNumber() {
document.getElementById("number").innerText = x;
}
</script>
</body>
</html>
Answer
<script>
function validateForm() {
var email1 = document.getElementById("email").value.trim();
var email2 = document.getElementById("email2").value.trim();
document.getElementById("emailError").innerHTML = "";
document.getElementById("emailError2").innerHTML = "";
return true;
}
</script>
Your solution should use the pattern attribute for input element.
Specify which method the form should use, method="get" or method="post", and the reason
why.
Answer
<!DOCTYPE html>
<html>
<head>
<title>University Fee Payment</title>
</head>
<body>
<button type="submit">Submit</button>
</form>
</body>
</html>
Answers
1)
SELECT FIRST_NAME,
DOB
FROM STUDENT;
2)
UPDATE STUDENT
SET LAST_NAME = ‘FRANK’
WHERE STUDENT_NUMBER = 2020567;
3)
DELETE FROM STUDENT
WHERE STUDENT_NUMBER = 2112345;
Assume that there is a JSON file, called student.json, which consists of information given below.
{"List":[{
"name":"John",
"age":31,
"pets":[
{ "animal":"dog", "name":"Fido" },
{ "animal":"cat", "name":"Felix" },
{ "animal":"hamster", "name":"Lightning" }
]
}
,
{"name":"ppp",
"age":31,
"pets":[
{ "animal":"fish", "name":"goldie" },
{ "animal":"cat", "name":"Fenolix" }
]
:
:
:
}
]
}
Answer
<!DOCTYPE html>
<html>
<head>
<title>Student Information</title>
</head>
<body>
<button onclick="loadSubjectInformation()">Load Student Information</button>
<div id="studentDiv"></div>
<script>
function loadSubjectInformation() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
processResult(this);
}
};
xhttp.open("GET", "student.json", true);
xhttp.send();
}
function processResult(xhttp) {
var jsonText = xhttp.responseText;
var studentObj = JSON.parse(jsonText);
display(studentObj);
}
function display(studentObj) {
var html = "<h1>Student Information</h1>";
html += "<table border='1'>";
html += "<tr><th>Age</th><th>Name</th><th>No. of Pets</th></tr>";
html += "</table>";
var studentDiv = document.getElementById("studentDiv");
studentDiv.innerHTML = html;
}
</script>
</body>
</html>