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