XML Schema anyElement


XML Schema 参考手册Complete XML Schema Reference

Definition and Usage

The any element enables creators to extend XML documents with elements not specified by the schema.

Element Information

  • Parent element: choice, sequence

Syntax

<any
id=ID
maxOccurs=nonNegativeInteger|unbounded
minOccurs=nonNegativeInteger
namespace=namespace
processContents=lax|skip|strict
any attributes
>

(annotation?)

</any>

(The ? symbol declares that the element may occur zero or one time within any element.)

Attributes Description
id Optional. Specifies a unique ID for the element.
maxOccurs Optional. Specifies the minimum number of times the any element may occur 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.
minOccurs Optional. Specifies the minimum number of times the any element can occur in the parent element. The value can be any number >= 0. Default value is 1
namespace

Optional. Specifies the namespace containing the elements that can be used. If no namespace is specified, ##any is the default. 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 this element can appear.
  • ##local - Elements that are not qualified by a namespace can appear.
  • ##targetNamespace - Elements from the target namespace of the parent element containing this element can appear.
  • A list of {URI references of namespaces, ##targetNamespace, ##local} - Elements from a space-separated list of namespaces can appear. The list can contain the following: URI references of namespaces, ##targetNamespace, and ##local.
processContents

Optional. An indicator that specifies how the application or XML processor should handle validation of an XML document against the elements specified by this any element. If the processContents attribute is not specified, it defaults to strict. If processContents is specified, it must be one of the following values:

  • strict - The XML processor must obtain the schema for the required namespaces and must validate all elements from these namespaces. (default)
  • lax - Same as strict; however, even if the schema cannot be obtained, no errors will occur.
  • skip - The XML processor does not attempt to validate any elements from the specified namespaces.
any attributes Optional. Specifies any other attributes with non-schema namespaces.

Example 1

The following example shows a declaration for 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>


XML Schema 参考手册Complete XML Schema Reference Other Extensions