Element Declaration

  • Declaring a Global Element

    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" ...>
      <xsd:element name="element-name" type="xsd:string"/>
    </schema>
    		    	

    An element declared as a direct schild of the schema root element is considered a 'global' element and is automatically declared in the target-namespace.

    A 'name' attribute is required for a global defined element.

    Global elements can be used as a root element for an XML Document.

  • Referencing a Global Element

    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" ...>
      <xsd:element name="element-name" type="xsd:string"/>
    
      <xsd:complexType name="complex-type">
        <xsd:sequence>
          <xsd:element ref="element-name"/>
        </xsd:sequence>
      </xsd:complexType>
    </schema>
    		    	

    Reuse a global defined element, by referencing the element, using the 'ref' attribute.

  • Specifying element occurrences.

    <xsd:element name="element-name" type="xsd:string" maxOccurs="unbounded" minOcurrs="0"/>
    		    	

    The 'minOccurs' attribute specifies the minimal number of times the element should appear (in the sequence). The value can be any integer value.

    The 'maxOccurs' attribute specifies the maximum number of times the element can appear (in the sequence). The value can be any integer value and the 'unbounded' string.

  • Elements can use the 'type' attribute to reference a simple or complex type.

    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" ...>
      <xsd:element name="element-name" type="complex-type"/>
    
      <xsd:complexType name="complex-type">
        <xsd:sequence>
          <xsd:element name="child-element-name" type="xsd:string"/>
        </xsd:sequence>
      </xsd:complexType>
    </schema>
    		    	

    Note

    The default value for the type attribute is 'xsd:string'.
  • Elements can use the child-element 'simpleType' to specify a simple-type locally.

    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" ...>
      <xsd:element name="element-name">
        <xsd:simpleType>
          ...
        </xsd:simpleType>
      </element>
    </schema>
    		    	
  • Elements can use the child-element 'complexType' to specify a complex-type locally.

    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" ...>
      <xsd:element name="element-name">
        <xsd:complexType>
          ...
        </xsd:complexType>
      </element>
    </schema>