<namespace> Element Definition

The namespace element defines a namespace used within the bound XML documents. Each namespace used within the documents must be defined using one of these elements. When marshalling to XML, the namespace definitions included in the binding are automatically added to the appropriate XML elements.

This works differently depending upon whether the namespace definition is in the binding element context, or that of a mapping element. If the namespace is the child of a mapping element it will be defined on the element associated with that mapping when it is marshalled. Only mapping elements that define an element name are allowed to have namespace child elements for this reason. If the namespace is a child of the binding element, it applies to all the top-level mappings defined within that binding. The effect is the same as if the namespace were instead present as a child element of every top-level mapping element.

Besides defining a namespace for the XML documents, the namespace element can also make that namespace the default for elements and/or attributes within the context of the definition. This is only a shortcut - a namespace URI can always be defined directly for each element or attribute, and a direct definition will always override the default defined by a namespace element. However, using a default namespace definition allows easy handling of common XML document structures. A default namespace for element names applies to the containing mapping element name as well as child element names.

The namespace element uses three unique attributes, but none of the common attribute groups.

Attributes

uri

This required attribute is the namespace URI being defined.

default

Optionally gives the default usage of this namespace, which must be "none" (only used where specified, the default if this attribute is not given), "elements" (default for elements only), "attributes" (default for attributes only), or "all" (both elements and attributes use this namespace by default).

prefix

This is the prefix to map to the namespace when marshalling. It is ignored when unmarshalling, since the namespace URI is used directly to identify elements and attributes. This attribute is required for namespaces in an output binding unless default="elements" is specified.

namespace elements are subject to the restrictions that namespaces with the same prefix cannot be defined in the same context, and no two namespaces can be defined with conflicting defaults within the same context (i.e., two namespaces each having either default="elements" or default="all", or two namespaces each having default="attributes" or default="all").