Attribute Declaration

  • Declaring a Global Attribute

    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" ...>
      <xsd:attribute name="attribute-name" type="xsd:string" use="optional" default="string-value"/>
    </schema>
    		    	

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

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

  • Referencing a Global Attribute

    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" ...>
      <xsd:attribute name="attribute-name" type="xsd:string" use="optional" default="string-value"/>
    
      <xsd:complexType name="complex-type">
        <xsd:attribute ref="attribute-name"/>
      </xsd:complexType>
    </schema>
    		    	

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

  • The 'use' attribute defines whether the attribute is optional (default), required or prohibited (only makes sense when specified on an element).

  • The 'default' attribute defines the attribute's default value, this attribute can only be specified if the 'use' attribute specifies optional.

  • The 'fixed' attribute defines the attribute's fixed value, this attribute can only be specified if the 'use' attribute specifies optional.

  • Attribute declarations can use the 'type' attribute to reference a simple type.

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

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