XML Schema anyAttributeElement


XML Schema 参考手册Complete XML Schema Reference Manual

Definition and Usage

The anyAttribute element enables authors to extend XML documents with attributes not specified by the schema.

Element Information

  • Parent elements: complexType, restriction (both simpleContent and complexContent), extension (both simpleContent and complexContent), attributeGroup

Syntax

<anyAttribute
id=ID
namespace=namespace
processContents=lax|skip|strict
any attributes
>

(annotation?)

</anyAttribute>

(The ? sign declares that the element can occur zero or one time inside the anyAttribute element.)

Attributes Description
id Optional. Specifies a unique ID for the element.
namespace

Optional. Specifies the namespace that contains 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 element's parent can appear.
  • ##local - Elements that are not namespace-qualified can appear.
  • ##targetNamespace - Elements from the target namespace of the parent element that contains this element can appear.
  • A list of {URI references of namespaces, ##targetNamespace, ##local} - Elements from a space-separated list of namespaces can appear. This list can contain the following: URI references of namespaces, ##targetNamespace, and ##local.
processContents

Optional. An indicator that instructs the application or XML processor how to handle validation of the XML document with respect to the elements specified by this 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 namespaces and must validate all elements from these namespaces. (default)
  • lax - Same as strict; however, no error will occur even if the schema cannot be obtained.
  • 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 theelement, authors can add any number of attributes to the "person" element:

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


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