public interface NamespaceAware
Namespacecontext. All the core JDOM classes are NamespaceAware (
Contentand subtypes, and
Attribute). You can use the methods that this interface provides to query the Namespace context.
JDOM2 introduces a consistency in reporting Namespace context. XML standards do not dictate any conditions on Namespace reporting or ordering, but consistency is valuable for user-friendliness. As a result JDOM2 imposes a useful order on the Namespace context for XML content.
The order for Namespace reporting is:
The XML namespace (bound to the prefix "xml" - see
Namespace.XML_NAMESPACE ) is always in every scope. It is always
Document, and in all other NamespaceAware instances it
is introduced if that content is detached.
See the individualised documentation for each implementing type for additional specific details. The following section is a description of how Namespaces are managed in the Element class.
All Elements are in a Namespace. Elements will be in
Namespace.NO_NAMESPACE unless a different Namespace was supplied as
part of the Element Constructor, or later modified by the
In addition to the Element's Namespace, there could be other Namespaces that are 'in scope' for the Element. The set of Namespaces that are in scope for an Element is the union of five sets:
There is always exactly one member of this set,
This set cannot be changed.
There is always exactly one member of this set, and it can be retrieved
or set with the methods
This is the set of distinct Namespaces that are used on Attributes. You
can modify the set by adding and removing Attributes to the Element.
This set is maintained by the two methods
|Inherited||This last set is somewhat dynamic because only those Namespaces on the parent Element which are not re-defined by this Element will be inherited. A Namespace is redefined by setting a new Namespace with the same prefix, but a different URI. If you set a Namespace on the Element (or add a Namespace declaration or set an Attribute) with the same prefix as another Namespace that would have been otherwise inherited, then that other Namespace will no longer be inherited.|
Since you cannot change the Namespace.XML_NAMESPACE, and the 'inherited' Namespace set is dynamic, the remaining Namespace sets are the most interesting from a JDOM perspective. JDOM validates all modifications that affect the Namespaces in scope for an Element. An IllegalAddException will be thrown if you attempt to add a new Namespace to the in-scope set if a different Namespace with the same prefix is already part of one of these three sets (Element, Attribute, or Additional).
|Modifier and Type||Method and Description|
Obtain a list of all namespaces that are in scope for this content, but were not introduced by this content.
Obtain a list of all namespaces that are in scope for the current content.
Obtain a list of all namespaces that are introduced to the XML tree by this node.
The contents of this list will always be the combination of getNamespacesIntroduced() and getNamespacesInherited().
NamespaceAware documentation for details on what the order of the
Namespaces will be in the returned list.
The contents of this list will always be a subset (but in the same order) of getNamespacesInScope(), and will never intersect getNamspacesInherited()
The contents of this list will always be a subset (but in the same order) of getNamespacesInScope(), and will never intersect getNamspacesIntroduced()
Copyright © 2015 Jason Hunter, Brett McLaughlin. All Rights Reserved.