Local and Global Declarations : Global Local « XML Schema « XML Tutorial






<?xml version="1.0" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <xsd:element name="animal" type="endType" />

  <xsd:element name="name" type="xsd:string" />

  <xsd:complexType name="endType">
    <xsd:sequence>
      <xsd:element name="animal">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element ref="name" minOccurs="0" />
            <xsd:element name="source" type="xsd:string" />
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="habitatType">
    <xsd:sequence>
      <xsd:element name="river">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element ref="name" minOccurs="1" maxOccurs="unbounded" />
            <xsd:element name="source" type="xsd:string" />
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>

Globally components appear on the first level below the xsd:schema element.
You can have two locally declared elements with the same name but different definitions.
Their context keeps them distinct. 
Global element declarations must have unique names. 
You must reference a global element in order to have it appear in a corresponding XML document.
When you define a complex type, you can either reference existing globally declared elements, or you can declare and define newelements on the spot. 
Locally declared elements are limited to the complex type definition in which they are declared.
Locally declared elements may not be used elsewhere in the schema.








3.96.Global Local
3.96.1.Global type versus Local type
3.96.2.An XML Schema Using Inline (or Local) Declarations
3.96.3.XML Schema Structures
3.96.4.Local and Global Declarations