Home > Articles > Web Services > XML

  • Print
  • + Share This
From the author of

Constraining the any Attribute

The first constraint that you can place on any is how the contents that are substituted will be treated by the XML processor. A number of options for the processContents attribute can set the level of validation of elements specified by an any element, as shown in the following table.

Option

Description

strict

The default value in the absence of any processContents attribute. The XML processor must have access to the schema for the namespaces of the substituted elements, and fully validate those elements against that schema.

lax

Similar to strict, with the exception that if no schema can be located for substituted elements, the XML parser simply checks for well-formed XML.

skip

The least-taxing validation method, which instructs the XML processor not to validate any elements from the specified namespaces.


The namespaces against which the contents can be validated are specified by a second optional attribute for the any element, called namespace. This attribute specifies the namespace of the elements that can validly be substituted for an any element within a document. The following table describes the settings for namespace.

Option

Description

##any

The default setting for the namespace attribute, which implies that elements from any namespace are allowed to exist in the placeholder specified by the any element.

##other

Specifying this value for the namespace attribute allows elements from any namespace except the namespace of the parent element (that is, not the targetNamespace of the parent).

##local

The substituted elements must come from no namespace.

##targetNamespace

Only elements from the namespace of the parent element can be contained.


You can combine some of the options above to make the available namespaces more configurable. That is, you can specify a space-separated list of valid namespace URIs (instead of ##any and ##other), plus optionally ##targetNamespace and ##local. Thus, you can restrict the namespaces that can validly be substituted for an any element to a list of one or more specific namespaces, if necessary.

  • + Share This
  • 🔖 Save To Your Account