Q.4. Considering the XML Schema shown below, answer the following questions:
a) Write an XML document that conforms to the rules of the xml schema given below. Add atleast two book elements.
b) Modify the XML schema to add an attribute “id” to the book element which is of the type string and is a mandatory.
c) In the XML schema, change the definition of the element “price” such that value of price cannot be lower than 10 or greater than 10000.
d) Explain how the schema could be modified so that the elements ‘genre’ and ‘review’ are made optional.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:books"
xmlns:bks="urn:books">
<xsd:element name="books" type="bks:BooksForm"/>
<xsd:complexType name="BooksForm">
<xsd:sequence>
<xsd:element name="book"
type="bks:BookForm"
minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="BookForm">
<xsd:sequence>
<xsd:element name="author" type="xsd:string"/>
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="genre" type="xsd:string"/>
<xsd:element name="price" type="xsd:float" />
<xsd:element name="pub_date" type="xsd:date" />
<xsd:element name="review" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
1) Add two book elements:
<xsd:element name="no_of_pages" type="xsd:integer" />
It will show the number of pages a book will contain. So its data type should be integer.
<xsd:element name="book_type" type="xsd:string"/>
It will show whether the book is a hard cover or paperback. So its data type is string.
2) Adding attribute id
<xsd:attribute name="id" type="xsd:string" use="required" />
Attributes are optional by default. So if we want them to be mandatory then we can use the "use" attribute.
3) Change the definition of price element
<xsd:element name="price">
<xsd:complexType>
<xsd: restriction base="xs:float">
<xsd: minInclusive value="10" />
<xsd: maxInclusive value="10000" />
</xsd:resrtriction>
</xsd:complexType>
</xsd:elelment>
4) Genre and review optional
<xsd:element name="genre" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="review" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
Q.4. Considering the XML Schema shown below, answer the following questions: a) Write an XML document...
1. Write an XML Schema for the following XML file satisfying the following requirements: a) comment element is required; b) publisher element should be of xsd:string type; c) price elements should be of xsd:float type. Validate the xml file against your XML Schema using the online validator: http://tools.decisionsoft.com/schemaValidate/. <?xml version="1.0"?> <bib> <comment>These books are still relevant </comment> <book year="1994"> <title>TCP/IP Illustrated</title> <author> <last>Stevens</last> <first>Tim</first> </author> <publisher>Addison-Wesley</publisher> <price discount="yes"> 65.95</price> </book> <book year="2003"> <title>Learning XML</title> <author> <last>Erik</last> <middle >T</middle > <first>Ray</first>...