I guess what Costello meant by re-use of the global elements in a schema is as follows �
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.test.org"
targetNamespace="http://www.test.org"
elementFormDefault="qualified">
<!�THIS ELEMENT WILL BE REUSED by globalElement2 �
<xsd:element name="globalElement1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="localElement3" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="globalType">
<xsd:sequence>
<xsd:element name="localElement1" type="xsd:string"/>
<xsd:element name="localElement2" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="globalElement3">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="localElement4" type="globalType"/>
<xsd:element name="localElement5" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="globalElement2">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="globalElement1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
If you look at globalElement2, it is referring to globalElement1. If you try replacing globalElement1 with localElement3, the schema validator will flag error as localElement3 is local to globalElement1. This is true for complexTypes also.
One more important thing for you to see here is that xmlns=http://www.test.org SHOULD be defined here as an attribute for <xsd:schema> element. Otherwise, we wouldn�t be referring to globalElement1 of
http://www.test.org namespace from globalElement2 and the validator will give you an error about this.
Also, only global elements will be seen from the instance documents as shown below �
Schema file �
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.test.org"
elementFormDefault="qualified">
<xsd:element name="globalElement1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="localElement3" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="globalType">
<xsd:sequence>
<xsd:element name="localElement1" type="xsd:string"/>
<xsd:element name="localElement2" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="globalElement3">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="localElement4" type="globalType"/>
<xsd:element name="localElement5" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="globalElement2">
<xsd:complexType>
<xsd:sequence>
<xsd:any/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
XML document �
<?xml version="1.0"?>
<globalElement2 xmlns="http://www.test.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://www.test.org
test.xsd">
<localElement3/>
</globalElement2>
If we try validating this xml file against the schema given above, we get an error about localElement3. This clearly shows that the instance document can only see the global elements in the schema. If you modify the stuff as shown below, it will be a valid instance document.
<?xml version="1.0"?>
<globalElement2 xmlns="http://www.test.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://www.test.org
test.xsd">
<globalElement1>
<localElement3/>
</globalElement1>
</globalElement2>