# XML Global Elements, Global Types, and Local Elements

An XML Schema type or element is considered global if it is a direct child of the schema element while an XML Schema type or element is considered local if it is not a direct child of the schema element (is nested to another element) as shown in the following XML Schema:

    <?xml version="1.0"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.acme.org/globalExample"
    xmlns="http://www.acme.org/globalExample"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified">
    	<xs:element name="globalElement">
    		<xs:complexType>
    			<xs:sequence>
    				<xs:element name="localElement"
    				minOccurs="1" maxOccurs="1"
    				type="xs:string" />
    			</xs:sequence>
    		</xs:complexType>
    	</xs:element>
    	<xs:complexType name="globalType">
    		<xs:sequence>
    			<xs:element name="anotherLocalElement"
    			minOccurs="0" maxOccurs="unbounded"
    			type="xs:string" />
    		</xs:sequence>
    	</xs:complexType>
    </xs:schema>

In the preceding example XML Schema, the globalElement is global because it is a direct child of the schema element while localElement is local because it is child of globalElement.

You can also define a global type as shown by the globalType element at the bottom of the preceding XML Schema. While you can only have one global element in an XML Schema, you can declare many elements (with different names) of the same global type in a single XML Schema.

The following table shows the graphical representations of these different XML components in the mapper.

Name | Representation in the Mapper | Name in Preceding Example XML Schema
--- | --- | ---
Global Element |  | localElement and anotherLocalElement
Local Element |  | globalElement
Global Type |  | globalType

Related Topics

Global Versus Local