XML AND JSON
Generate XSD For Breakfast Menu
Generate XSD for the given XML document
<?xml version="1.0" encoding="UTF-8"?>
<breakfast_menu>
<food>
<name>Turfle waffles</name>
<price>$5.95</price>
<description>This two turfle which has 2 famous product is with real choco and maple
syrup</description>
<calories>650</calories>
</food>
<food>
<name>Strawberry Belgian Waffles</name>
<price>$24.6</price>
<description>Light Belgian waffles covered with strawberries and whipped cream</description>
<calories>900</calories>
</food>
<food>
<name>Berry-Berry Belgian Waffles</name>
<price>$4.78</price>
<description>Light Belgian waffles covered with an assortment of fresh berries and whipped
cream</description>
<calories>400</calories>
</food>
<food>
<name>Fried Toast</name>
<price>$7.68</price>
<description>Thick slices made from our homemade wheat dough bread</description>
<calories>250</calories>
</food>
<food>
<name>Homestyle Breakfast</name>
<price>$7.95</price>
<description>Two eggs, bacon or sausage, toast, and England popular hash
browns</description>
<calories>1500</calories>
</food>
</breakfast_menu>
ANSWER
food.xsd
1 <?xml version="1.0" encoding="utf-8"?>
2 <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema" >
3 <xs:element name="breakfast_menu">
4 <xs:complexType>
5 <xs:sequence>
6 <xs:element maxOccurs="unbounded" name ="food">
7 <xs:complexType>
8 <xs:sequence>
9 <xs:element name="name" type="xs:string"/>
10 <xs:element name="price" type="xs:string"/>
11 <xs:element name="description" type="xs:string"/>
12 <xs:element name="calories" type="xs:unsignedShort"/>
13 </xs:sequence>
14 </xs:complexType>
15 </xs:element>
16 </xs:sequence>
17 </xs:complexType>
18 </xs:element>
19 </xs:schema>
Generate XSD for Persons
Generate XSD for the following XML.
XYZ organization wants to store the details of persons in an xml file. The following scenario helps in
designing the XML document.
Here PersonList is the root tag. PersonList contains the entry of each person with adhaarno, name,
age and address.
<?xml version="1.0" encoding="UTF-8"?>
<PersonList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="PersonList.xsd">
<Person>
<adhaarno>414356782345</adhaarno>
<name>
<firstname>Zeenath</firstname>
</name>
<age>28</age>
<address>
<doorno>33</doorno>
<street>Raidu Street</street>
<city>coimbatore</city>
<pincode>641039</pincode>
</address>
</Person>
<Person Category="seniorcitizen">
<adhaarno>414356782345</adhaarno>
<name>
<firstname>Simon</firstname>
</name>
<age>75</age>
<address>
<doorno>7</doorno>
<street>Raja Street</street>
<city>Chennai</city>
<pincode>600005</pincode>
</address>
</Person>
<Person>
<adhaarno>414356782345</adhaarno>
<name>
<lastname>Varma</lastname>
</name>
<age>25</age>
<address>
<doorno>25</doorno>
<street>cox street</street>
<city>Bangalore</city>
<pincode>560025</pincode>
</address>
</Person>
</PersonList>
ANSWER
PersonList.xsd
1 <?xml version="1.0" encoding="utf-8"?>
2 <xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" attributeFormDefault="unqualified"
elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
3 <xs:element name="PersonList">
4 <xs:complexType>
5 <xs:sequence>
6 <xs:element maxOccurs="unbounded" name="Person">
7 <xs:complexType>
8 <xs:sequence>
9 <xs:element name="adhaarno" type="xs:unsignedLong" />
10 <xs:element name="name">
11 <xs:complexType>
12 <xs:sequence>
13 <xs:element minOccurs="0" name="lastname" type="xs:string" />
14 <xs:element minOccurs="0" name="firstname" type="xs:string" />
15 </xs:sequence>
16 </xs:complexType>
17 </xs:element>
18 <xs:element name="age" type="xs:unsignedByte" />
19 <xs:element name="address">
20 <xs:complexType>
21 <xs:sequence>
22 <xs:element name="doorno" type="xs:unsignedByte" />
23 <xs:element name="street" type="xs:string" />
24 <xs:element name="city" type="xs:string" />
25 <xs:element name="pincode" type ="xs:unsignedInt" />
26 </xs:sequence>
27 </xs:complexType>
28 </xs:element>
29 </xs:sequence>
30 <xs:attribute name="Category" type="xs:string" use="optional" />
31 </xs:complexType>
32 </xs:element>
33 </xs:sequence>
34 </xs:complexType>
35 </xs:element>
36 </xs:schema>
37
Generate XSD for Students
Generate XSD for the following XML.
XYZ School wants to store the details of students in an xml file. The following scenario helps in
designing the XML document.
Here StudentList is the root tag. StudentList contains the entry of each student with rollno, name,
age, address and department.
<?xml version="1.0" encoding="UTF-8"?>
<StudentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="StudentList.xsd">
<Student rollno="2017CSE0055">
<name>
<firstname>Savitha</firstname>
</name>
<age>20</age>
<address>
<doorno>35</doorno>
<street>NRG Street</street>
<city>coimbatore</city>
<pincode>641038</pincode>
</address>
<department>CSE</department>
</Student>
<Student rollno="2017ECE1050">
<name>
<firstname>Vinitha</firstname>
</name>
<age>21</age>
<address>
<doorno>9</doorno>
<street>Randy Street</street>
<city>Chennai</city>
<pincode>600025</pincode>
</address>
<department>ECE</department>
</Student>
<Student rollno="2017EEE2044">
<name>
<firstname>Steve</firstname>
<lastname> Johnson </lastname>
</name>
<age>19</age>
<address>
<doorno>15</doorno>
<street>CMH Road</street>
<city>Bangalore</city>
<pincode>560039</pincode>
</address>
<department>EEE</department>
</Student>
</StudentList>
ANSWER
StudentList.xsd
1 <?xml version="1.0" encoding="utf-8"?>
2 <xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" attributeFormDefault="unqualified"
elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
3 <xs:element name="StudentList">
4 <xs:complexType>
5 <xs:sequence>
6 <xs:element maxOccurs="unbounded" name="Student">
7 <xs:complexType>
8 <xs:sequence>
9 <xs:element name="name">
10 <xs:complexType>
11 <xs:sequence>
12 <xs:element name="firstname" type="xs:string" />
13 <xs:element minOccurs="0" name="lastname" type="xs:string" />
14 </xs:sequence>
15 </xs:complexType>
16 </xs:element>
17 <xs:element name="age" type="xs:unsignedByte"/>
18 <xs:element name="address">
19 <xs:complexType>
20 <xs:sequence>
21 <xs:element name="doorno" type="xs:unsignedByte" />
22 <xs:element name="street" type="xs:string"/>
23 <xs:element name="city" type="xs:string" />
24 <xs:element name="pincode" type="xs:unsignedInt"/>
25 </xs:sequence>
26 </xs:complexType>
27 </xs:element>
28 <xs:element name="department" type="xs:string" />
29 </xs:sequence>
30 <xs:attribute name ="rollno" type="xs:string" use="required" />
31 </xs:complexType>
32 </xs:element>
33 </xs:sequence>
34 </xs:complexType>
35 </xs:element>
36 </xs:schema>
Generate XSD For Mobile Store
<?xml version="1.0" encoding="UTF-8"?>
<mobilestore>
<mobile>
<brand>Nokia</brand>
<os>Symbian</os>
<model>C6</model>
<ram>1gb</ram>
<internal>8gb</internal>
</mobile>
<mobile>
<brand>Samsung</brand>
<os>Android</os>
<model>Galaxy</model>
<ram>2gb</ram>
<internal>8gb</internal>
</mobile>
<mobile>
<brand>Sony</brand>
<os>Android</os>
<model>Experia</model>
<ram>512mb</ram>
<internal>16gb</internal>
</mobile>
</mobilestore>
ANSWER
mobile.xsd
1 <?xml version="1.0" encoding="utf-8"?>
2 <xs:schema attributeFormDefault ="unqualified" elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
3 <xs:element name="mobilestore">
4 <xs:complexType>
5 <xs:sequence>
6 <xs:element maxOccurs="unbounded" name="mobile">
7 <xs:complexType>
8 <xs:sequence>
9 <xs:element name="brand" type="xs:string" />
10 <xs:element name="os" type="xs:string"/>
11 <xs:element name="model" type="xs:string" />
12 <xs:element name="ram" type="xs:string" />
13 <xs:element name="internal" type="xs:string"/>
14 </xs:sequence>
15 </xs:complexType>
16 </xs:element>
17 </xs:sequence>
18 </xs:complexType>
19 </xs:element>
20 </xs:schema>
Generate XSD 2
Generate XSD for the following XML document
<?xml version="1.0" encoding="UTF-8"?>
<!-- <!DOCTYPE hotels SYSTEM "hotel.dtd"> -->
<hotels>
<hotel>
<ID>1</ID>
<Name> TAJ GANJ </Name>
<Stars>3</Stars>
<Facilities>Restaurant,Parking,Internet</Facilities>
<Address>Taj Ganj,FFatehabad Road Agra Uttar Pradesh 282001</Address>
<Type>budget</Type>
<Available>true</Available>
</hotel>
<hotel>
<ID>2</ID>
<Name> TAJ EXOTICA </Name>
<Stars>5</Stars>
<Facilities>Indian therapies,Yoga and meditation,Spaindulges,Parking</Facilities>
<Address>CalwaddoBenaulim, Salcete Goa 403716</Address>
<Type>luxury</Type>
<Available>false</Available>
</hotel>
<hotel>
<ID>3</ID>
<Name> VIVANTA by TAJ </Name>
<Stars>3</Stars>
<Facilities>Parking,Restaurant,Internet,Chinese Restaurant, Party Lawn</Facilities>
<Address>105, Race Course Road Coimbatore TamilNadu 641018</Address>
<Type>medium luxury</Type>
<Available>true</Available>
</hotel>
<hotel>
<ID>4</ID>
<Name> TAJ DECCAN </Name>
<Stars>4</Stars>
<Facilities>Parking,Fitnesscenter,Meetingrooms,Private dining for party</Facilities>
<Address>Road No. 1, Banjara Hills Hyderabad Telangana State 500034</Address>
<Type>Budget</Type>
<Available>true</Available>
</hotel>
<hotel>
<ID>5</ID>
<Name> TAJ BEKAL RESORT </Name>
<Stars>4</Stars>
<Facilities>Spa ,Internet ,Yoga and meditation,parking,internet</Facilities>
<Address>Kappil Beach Kasargod Kerala 671319</Address>
<Type>Luxury</Type>
<Available>false</Available>
</hotel>
</hotels>
ANSWER
hotels.xsd
1 <?xml version="1.0" encoding="utf-8"?>
2 <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
3 <xs:element name="hotels">
4 <xs:complexType>
5 <xs:sequence>
6 <xs:element maxOccurs="unbounded" name="hotel">
7 <xs:complexType>
8 <xs:sequence>
9 <xs:element name="ID" type="xs:unsignedByte"/>
10 <xs:element name="Name" type ="xs:string" />
11 <xs:element name="Stars" type="xs:string" />
12 <xs:element name="Facilities" type="xs:string" />
13 <xs:element name="Address" type="xs:string" />
14 <xs:element name="Type" type="xs:string" />
15 <xs:element name="Available" type="xs:boolean" />
16 </xs:sequence>
17 </xs:complexType>
18 </xs:element>
19 </xs:sequence>
20 </xs:complexType>
21 </xs:element>
22 </xs:schema>
Generate XSD 4
Generate an XSD for the following XML document
<?xml version="1.0" encoding="UTF-8"?>
<company>
<employee>
<id>101</id>
<name>Ram</name>
<salary>10000</salary>
<email>[email protected]</email>
</employee>
<employee>
<id>102</id>
<name>Dinesh</name>
<salary>20000</salary>
<email>[email protected]</email>
</employee>
<employee>
<id>103</id>
<name>sathish</name>
<salary>20000</salary>
<email>[email protected]</email>
</employee>
<employee>
<id>104</id>
<name>Praveen</name>
<salary>20000</salary>
<email>[email protected]</email>
</employee>
</company>
ANSWER
employee.xsd
1 <?xml version ="1.0" encoding="utf-8"?>
2 <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
3 <xs:element name="company">
4 <xs:complexType>
5 <xs:sequence>
6 <xs:element maxOccurs="unbounded" name="employee">
7 <xs:complexType>
8 <xs:sequence>
9 <xs:element name="id" type="xs:unsignedByte"/>
10 <xs:element name="name" type="xs:string"/>
11 <xs:element name="salary" type="xs:unsignedShort"/>
12 <xs:element name="email" type="xs:string"/>
13 </xs:sequence>
14 </xs:complexType>
15 </xs:element>
16 </xs:sequence>
17 </xs:complexType>
18 </xs:element>
19 </xs:schema>