Designing Your own XML Schema: Learn the Essentials - XML Schema: a simple practical example
(Page 4 of 6 )
Since you understand some basics about XML schema by now, we should extend our discussion to a more practical example. Let us have a look at the following XML schema now:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Employees">
<xs:annotation>
<xs:documentation>Contains All Employee information</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="Employee">
<xs:complexType>
<xs:sequence>
<xs:element name="ID" type="xs:string"/>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Age" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Now you can see that I extended my previous example to define the “complextype.” According to the above example, the document root element would be “Employees.” The element “Employees” internally contains another element, “Employee.” And finally, the element “Employee” internally contains three more elements: “ID,” “Name” and “Age.”
You should observe that “ID,” “Name” and “Age” are defined with “simple types” rather than with “complex types.” The only complex elements are “Employees” and “Employee.”
Now, how would an XML document look when made to conform to the above XML Schema? The following would be a sample XML document which conforms to the XML Schema above.
<?xml version="1.0" encoding="UTF-8"?>
<Employees xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\Employees.xsd">
<Employee>
<ID>1001</ID>
<Name>Jag</Name>
<Age>27</Age>
</Employee>
</Employees>
Next: XML Schema: a simple practical example continued >>
More XML Articles
More By Jagadish Chaterjee