1.Write an xml schema for the following xml file.

Book.xml

<BOOK>

<BOOK_NAME>Computer Networks</BOOK_NAME>

<AUTHOR>Andrew Tanenbaum</AUTHOR>

<PUBLISHER>Pearson Education</PUBLISHER>

<PUBLISHINGDATE>2010-02-10</PUBLISHINGDATE >

</BOOK>

2. Modify the schema for the above xml so that the BOOK_NAME contains only “Computer Networks” or “Network Programming” or “Internet Programming”.

Also the length of the publisher should not exceed 10 characters.

Solution 1.

Book1.xsd

<xsd:schema xmlns:xsd=”http://www.w3.org/2001/XMLSchema”&gt;

<xsd:element name=”BOOK”>

<xsd:complexType>

<xsd:sequence>

<xsd:element name=”BOOK_NAME” type=”xsd:string”/>

<xsd:element name=”AUTHOR” type=”xsd:string”/>

<xsd:element name=”PUBLISHER” type=”xsd:string”/>

<xsd:element name=”PUBLISHINGDATE” type=”xsd:date”/>

</xsd:sequence>

</xsd:complexType>

</xsd:element>

</xsd:schema>


Solution2

Book2.xsd

<xsd:schema xmlns:xsd=”http://www.w3.org/2001/XMLSchema”&gt;

<xsd:element name=”BOOK”>

<xsd:complexType>

<xsd:sequence>

<xsd:element name=”BOOK_NAME” type=”BookNameType” />

<xsd:element name=”AUTHOR” type=”xsd:string” />

<xsd:element name=”PUBLISHER” type=”PublisherLength” />

<xsd:element name=”PUBLISHINGDATE” type=”xsd:date” />

</xsd:sequence>

</xsd:complexType>

</xsd:element>


<xsd:simpleType name=”BookNameType”>

<xsd:restriction base=”xsd:string”>

<xsd:enumeration value=”Computer Networks”></xsd:enumeration>

<xsd:enumeration value=”Network Programming”></xsd:enumeration>

<xsd:enumeration value=”Internet Programming”></xsd:enumeration>

</xsd:restriction>

</xsd:simpleType>


<xsd:simpleType name=”PublisherLength”>

<xsd:restriction base=”xsd:string”>

<xsd:maxLength value=”10″ />

</xsd:restriction>

</xsd:simpleType>


</xsd:schema>


Advertisements