Introduction to Relations in XML Schema - Combining two different roots or hierarchies in a single XML Schema: the problem (Page 3 of 5 )
This was one of the main problems I faced earlier while designing an XML schema. An XML schema supports opening up several root elements (with their own primary keys). But an XML document would never permit it! A proper XML document should always be defined with only one root element.
To understand this, let us consider that I would like to have two hierarchies within a single XML document. The first focuses on “dept” and the other on “emp.” Let us consider the following XML schema:
From the above schema, you can understand that the schema allows both “dept” and “employee.” But if you try to create an XML document based on the above schema (with both “dept” and “employee”), the parser would return an error!
Any well-defined XML document could start with only one root element, not more than that. So, from the above case, we can start with either “dept” or “employee,” but not both. This raises a problem when defining a schema (with both “dept” and “employee”) to support with XML.
The problem can be easily solved by embedding both of the hierarchies under a single root element! The next section shows you how to do this.