XML Schema 'anyAttribute' element
Definition and usage
The 'anyAttribute' element allows creators to extend the XML document with attributes not specified by the schema.
Element information
Item | Description |
---|---|
Occurrence times | Unrestricted |
Parent element | complexType, restriction (simpleContent), extension (simpleContent), restriction (complexContent), extension (complexContent), attributeGroup |
Content | annotation |
Syntax
<anyAttribute id=ID namespace=namespace processContents=lax|skip|strict any attributes > (annotation?) </anyAttribute>
(? symbol indicates that the element can appear zero or one time within the anyAttribute element.)
Attributes
id
Optional. Specifies a unique ID for the element.
namespace
Optional. Specifies the namespace of the elements that can be used. If no namespace is specified, ##any is the default value. 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 contain the following content: URI references to the namespaces ##targetNamespace and ##local.
processContents
Optional. An indicator that tells the application or XML processor how to handle the validation of the XML document based on the elements specified by the 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 required for the namespace and must validate all elements from these namespaces. (Default)
- lax - Same as strict; however, no error occurs even if the schema cannot be obtained.
- skip - The XML processor does not attempt to validate all elements from the specified namespace.
any attributes
Optional. Specifies any other attributes with non-schema namespaces.
Instance
The following example demonstrates a declaration for the "person" element. By using the <anyAttribute> element, the creator can add an arbitrary 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>