The document discusses several examples of using XML including internal and external DTDs to define bookstore and employee data, as well as using XML Schema to define message and employee details. XML documents are provided as examples to demonstrate using the defined DTDs and schemas. The last section shows applying CSS styling to an XML document.
9. P a g e | 64
5. XML Schema and XML document for message details
Message XSD
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.messages.org/note"
elementFormDefault="qualified"
xmlns="http://www.messages.org/note">
<xsd:element name="note">
<xsd:complexType>
<xsd:sequence>
<xsd: element name="to" type="xsd:string" maxOccurs="unbounded"/>
<xsd: element name="from" type="xsd:string" />
<xsd: element name="heading" type="xsd:string" />
<xsd: element name="body" type="xsd:string" />
</xsd:sequence>
<xsd: attribute name="id" type="xsd: integer" use="required" />
<xsd: attribute name="date" type="xsd: date" />
</xsd:complexType>
</xsd:element>
<xsd:element name="messages">
<xsd:complexType>
<xsd:sequence>
<xsd: element ref="note" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Message XML
<?xml version="1.0" encoding="utf-8"?>
<messages xmlns="http://www.messages.org/note"
xmlns:xsi="http://www.w3.org/2001/XMLSchema?-instance"
xsi:schemaLocation="http://www.message.org/note message.xsd">
<note id="111" date="2011-09-14">
<to> Robert Sebesta </to>
<to> Tanenbaum </to>
<form> Herbert schildt </form>
<heading> Reminder</heading>
<body> Conference Meeting of authors on 5pm tomorrow</body>
</note>
<note id="112">
<to> Kernighan </to>
M.J.C.E.T 04-09-8127L
10. P a g e | 65
<form> Ritchie </form>
<heading> Important News </heading>
<body> Tomorrow's meeting is cancelled </body>
</note>
</messages>
M.J.C.E.T 04-09-8127L
11. P a g e | 66
6. XML Schema and XML document for employee details
EMP XSD
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.employee.org/emp"
elementFormDefault="qualified"
xmlns="http://www.employee.org/emp">
<xsd:element name="name">
<xsd:complexType>
<xsd:sequence>
<xsd: element name="first" type="xsd:string"/>
<xsd: element name="middle" type="xsd:string" minOccurs="0"/>
<xsd: element name="last" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="address">
<xsd:complexType>
<xsd:sequence>
<xsd: element name="flatno" type="xsd:string"/>
<xsd: element name="street" type="xsd:string"/>
<xsd: element name="city" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="contact-info">
<xsd:complexType>
<xsd:sequence>
<xsd: element name="landline" type="xsd:integer" minOccurs="0"/>
<xsd: element name="mobile" type="xsd:integer" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="agetype">
<xsd:restriction base="xsd:positiveInteger">
<xsd:minInclusive value="20">
<xsd:maxInclusive value="65">
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="gendertype">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="male">
M.J.C.E.T 04-09-8127L
12. P a g e | 67
<xsd:enumeration value="female">
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="employee">
<xsd:complexType>
<xsd:sequence>
<xsd: element ref="name"/>
<xsd: element name="age" type="agetype"/>
<xsd: element name="salary" type="xsd:integer"/>
<xsd: element name="designation" type="xsd:string"/>
<xsd: element name="dept" type="xsd:string"/>
<xsd: element ref="address"/>
<xsd: element ref="contact-info"/>
<xsd: element name="email-id" type="xsd:string"/>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:integer" use="required" />
<xsd:attribute name="gender" type="gendertype" default="male" />
<xsd:attribute name="organization" type="xsd:string" fixed="mjcet" />
</xsd:complexType>
</xsd:element>
<xsd:element name="emp-db">
<xsd:complexType>
<xsd:sequence>
<xsd: element ref="employee" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
EMP XML
<?xml version="1.0" encoding="utf-8"?>
<emp-db xmlns="http://www.employee.org/emp"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.employee.org/emp emp.xsd">
<employee id="100" gender="male" organization="mjcet">
<name>
<first> Robert </first>
<second> schildt </second>
<last> sebesta </last>
</name>
<age> 30 </age>
<salary> 45000 </salary>
<designation> manager </designation>
<dept> cse </dept>
M.J.C.E.T 04-09-8127L
15. P a g e | 70
7. XML document using CSS
Style.css
messages {color:green;}
note {background-color:lightgrey;}
to {font-style:italic; display:block;}
from {font-variant:small-caps; display:block;}
heading {text-decoration:underline; display:block;}
body {font-weight:bold; display:block;}
Message XML
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="style.css"?>
<messagses>
<note>
<to> Robert Sebesta </to>
<form> Herbert schildt </form>
<heading> Reminder</heading>
<body> Conference Meeting of authors on 5pm tomorrow</body>
</note>
</messagses>
M.J.C.E.T 04-09-8127L