To illustrate this feature and see its implication,
let's look again at the example that
we've used throughout this chapter:
<?xml version="1.0"?>
<library xmlns="http://dyomedea.com/ns/library">
<book id="b0836217462">
<title>
Being a Dog Is a Full-Time Job
</title>
<authors>
<person id="CMS">
<name>
Charles M Schulz
</name>
</person>
</authors>
</book>
</library>
If we want a library of schema parts that describe a person and can
be included within several vocabularies, we can include a piece of
schema that has no target namespace. This piece of schema would be
something like the following (note that we do not define any target
namespace):
<?xml version="1.0"?>
<xs:schema elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
</xs:sequence>
<xs:attribute name="id" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
And the including schema would look similar to the following example:
<?xml version="1.0"?>
<xs:schema targetNamespace="http://dyomedea.com/ns/library"
elementFormDefault="qualified"
xmlns="http://dyomedea.com/ns/library"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="very-simple-1-ns-ppl.xsd"/>
<xs:element name="library">
<xs:complexType>
<xs:sequence>
<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="authors">
<xs:complexType>
<xs:sequence>
<xs:element ref="person"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="id" type="xs:ID"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
While this looks very easy and neat, we may wonder if we are really
building something modular. Including a piece of schema is similar to
including a C header file. While this is slightly better than a
copy/paste, the level of modularity that can be achieved in this way
is very restricted.
The namespace of the element person is the
namespace given to our library. An application cannot guess from
looking at the instance document that this element is the same as a
person element that it will find in another
document describing, for example, an employee.
Looking at the modified infoset and checking the datatype
doesn't help either, since the datatype will be
defined as a datatype from a schema with the target namespace of our
library, and won't match other target namespaces,
including the same piece of schema.