CS311 Assignment 2 Solution and Discussion
-
Assignment No. 02
Semester: Fall 2019
Introduction to Web Services Development – CS311
Total Marks: 20Due Date: 4/12/2019
Objectives:
Understand and get hands on experience of
• XML schema
• Generating XML schema (XSD) of a given XML
• Generate XML using PHP
Instructions:
Please read the following instructions carefully before submitting assignment:
It should be clear that your assignment will not get any credit if: The assignment is submitted after due date.
The assignment is submitted via email.
The assignment is copied from Internet or from any other student.
The submitted assignment does not open or file is corrupt.
It is in some format other than .doc/.docx.Note: All types of plagiarism are strictly prohibited.
For any query about the assignment, contact at [email protected]
Consider the well-formed XML given below. You are required to:
- Write XML Schema (.xsd) code for the given XML
- Generate the following XML on a server as output using PHP
<?xml version="1.0"?> <BookStore> <Book> <Title>Introduction to Computing</Title> <Course>CS101</Course> <Year>2016</Year> <Publisher>Virtual University of Pakistan</Publisher> <Author>Dr Tanveer Ahmad</Author> </Book> <Book> <Title>Object Oriented Programming</Title> <Course>CS304</Course> <Year>2017</Year> <Publisher>Virtual University of Pakistan</Publisher> <Author>Dr Shafeeq</Author> </Book> </BookStore>
Assignment Uploading Instructions:
• You need to upload your assignment in .doc/.docx file format.
• Copy your code for both the questions and paste it in word file(.doc/.docx) and then upload your assignmentPlease note that due date of assignment will not extend, so do not wait for last date and submit your solution as quickly as possible.
-
Solution Ideas:
- Write XML Schema (.xsd) code for the given XML
Answer
XSD Code <?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="BookStore"> <xs:complexType> <xs:sequence> <xs:element name="Book" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="Title" type="xs:string"/> <xs:element name="Course" type="xs:string"/> <xs:element name="Year" type="xs:unsignedShort"/> <xs:element name="Publisher" type="xs:string"/> <xs:element name="Author" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
- Generate the following XML on a server as output using PHP
Answer
PHP CODE
<?php header("Content-type: text/xml"); echo"<BookStore>"; echo"<Book>"; echo"<Title>Introduction to Computing</Title>"; echo"<Course>CS101</Course>"; echo"<Year>2016</Year>"; echo"<Publisher>Virtual University of Pakistan </Publisher>"; echo"<Author>Dr Tanveer Ahmad</Author>"; echo"</Book>"; echo"<Book>"; echo"<Title>Object Oriented Programming</Title>"; echo"<Course>CS304</Course>"; echo"<Year>2017</Year>"; echo"<Publisher>Virtual University of Pakistan</Publisher>"; echo"<Author>Dr Shafeeq</Author>"; echo"</Book>"; echo"</BookStore>"; ?>
PHP OUTPUT