public interface NamespaceAware
Namespace
context. All the core JDOM classes are NamespaceAware
(Parent
and subtypes, Content
and 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
introduced in 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.
Namespace.NO_NAMESPACE
unless a different Namespace was supplied as
part of the Element Constructor, or later modified by the
Element.setNamespace(Namespace)
method.
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:
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).限定符和类型 | 方法和说明 |
---|---|
java.util.List<Namespace> |
getNamespacesInherited()
Obtain a list of all namespaces that are in scope for this content, but
were not introduced by this content.
|
java.util.List<Namespace> |
getNamespacesInScope()
Obtain a list of all namespaces that are in scope for the current
content.
|
java.util.List<Namespace> |
getNamespacesIntroduced()
Obtain a list of all namespaces that are introduced to the XML tree by
this node.
|
java.util.List<Namespace> getNamespacesInScope()
The contents of this list will always be the combination of getNamespacesIntroduced() and getNamespacesInherited().
See NamespaceAware
documentation for details on what the order of the
Namespaces will be in the returned list.
java.util.List<Namespace> getNamespacesIntroduced()
The contents of this list will always be a subset (but in the same order) of getNamespacesInScope(), and will never intersect getNamspacesInherited()
java.util.List<Namespace> getNamespacesInherited()
The contents of this list will always be a subset (but in the same order) of getNamespacesInScope(), and will never intersect getNamspacesIntroduced()