XML Schema any element

Definition and usage

The any element allows any element from the specified namespace to be displayed within elements containing sequence or choice.

This element allows creators to extend XML documents by using elements not specified by the schema.

Element information

Item Description
Occurrence Unrestricted
Parent element choice, sequence
Content annotation

Syntax

<any
id=ID
maxOccurs=nonNegativeInteger|unbounded
minOccurs=nonNegativeInteger
namespace=namespace
processContents=lax|skip|strict
any attributes
>
(annotation?)
</any>

(The ? symbol declaration element can appear zero or once within any element.)

Attribute

id

Optional. Defines a unique ID for the element.

maxOccurs

Optional. Defines the maximum number of times the any element can appear in the parent element. The value can be an integer greater than or equal to zero. To place no limit on the maximum count, use the string "unbounded". The default value is 1.

minOccurs

Optional. Defines the minimum number of times the any element can appear in the parent element. The value can be an integer greater than or equal to zero. To specify that the any group is optional, set this attribute to zero. The default value is 1.

namespace

Optional. Defines the namespace of the elements that can be used. If no namespace is specified, the default value is ##any. If a namespace is specified, it must be one of the following values:

  • ##any - Elements from any namespace can appear (default).
  • ##other - Elements from any namespace other than the target namespace of the parent element of the element can appear.
  • ##local - Elements not qualified by a namespace can appear.
  • ##targetNamespace - Elements from the target namespace of the parent element containing the element can appear.
  • A list of {URI references of namespaces, ##targetNamespace, ##local} - Elements from the namespace list separated by spaces can appear. The list can include the following: URI references to the namespaces ##targetNamespace and ##local.

processContents

Optional. An indicator that tells the application or XML processor how to validate the XML document based on the elements specified by the any element. If the processContents attribute is not specified, the default is strict. If processContents is specified, it must be one of the following values:

  • strict - The XML processor must obtain the schema for the required namespace and must validate all elements from these namespaces. (Default)
  • lax - Same as strict; however, no error will occur even if the schema cannot be accessed.
  • skip - The XML processor does not validate all elements from the specified namespace.

any attributes

Optional. Defines any other attributes with non-schema namespaces.

Example

The following example demonstrates a declaration of the "person" element. By using the <any> element, creators can extend the content of "person" with any element (after <lastname>):

<xs:element name="person">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="firstname" type="xs:string"/>
      <xs:element name="lastname" type="xs:string"/>
      <xs:any minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>