XML and Json
XML and Json
<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>
<price>$24.6</price>
<calories>900</calories>
</food>
<food>
<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>
<calories>250</calories>
</food>
<food>
<name>Homestyle Breakfast</name>
<price>$7.95</price>
<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>
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.
<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
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.
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>
<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
<hotels>
<hotel>
<ID>1</ID>
<Stars>3</Stars>
<Facilities>Restaurant,Parking,Internet</Facilities>
<Type>budget</Type>
<Available>true</Available>
</hotel>
<hotel>
<ID>2</ID>
<Stars>5</Stars>
<Type>luxury</Type>
<Available>false</Available>
</hotel>
<hotel>
<ID>3</ID>
<Stars>3</Stars>
<Type>medium luxury</Type>
<Available>true</Available>
</hotel>
<hotel>
<ID>4</ID>
<Stars>4</Stars>
<Type>Budget</Type>
<Available>true</Available>
</hotel>
<hotel>
<ID>5</ID>
<Stars>4</Stars>
<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>