Designing Your own XML Schema: Learn the Essentials - XML Schema: the complex way
(Page 3 of 6 )
The previous section covered defining the schema in a very simple manner with simple data types. Now, we need to extend this to “complex” types.
“Simple” types are generally used for defining simple XML structures of some standard data types. As your schema grows with several other complicated structures (and might even be nested within them), the “simple” types may not be quite enough to handle the entire schema accurately.
Complicated structures generally include nested structures, relations between structures, attributes, links to other structures in external schemas, and so on. All these complications cannot be handled by “simple” types at all. This requires the “complex” type of declarations.
Let us start with a tiny “complex” type XSD declaration:
<?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:element>
</xs:schema>
The above defines a new root element, “Employees,” as a complex type (but doesn't yet define what type or how complex it is). The “annotation” is generally used for documenting your definition. Though it is optional, it is a good practice to maintain “documentation” with every definition. This would also help other users (or consumers) of several other heterogeneous environments to understand your schema better.
Even though the above schema is not very useful, I just meant it for a simple example. Let us now look into more practical scenarios.
Next: XML Schema: a simple practical example >>
More XML Articles
More By Jagadish Chaterjee