public final class NamespaceSupport
extends java.lang.Object
| Modifier | Constructor and Description |
|---|---|
private |
NamespaceSupport()
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
appendNamespaceDeclaration(org.w3c.dom.Element element,
java.lang.String namespaceURI,
java.lang.String prefix)
Adds a namespace declaration (xmlns:) attribute to the given element.
|
static java.lang.String |
lookupNamespaceURI(org.w3c.dom.Element startingElement,
org.w3c.dom.Element stoppingElement,
java.lang.String prefix)
Looks up the namespace URI associated with the given prefix starting at the given element.
|
static java.lang.String |
lookupPrefix(org.w3c.dom.Element startingElement,
org.w3c.dom.Element stopingElement,
java.lang.String namespaceURI)
Looks up the namespace prefix associated with the given URI starting at the given element.
|
static void |
rootNamespaces(org.w3c.dom.Element domElement)
Ensures that all the visibly used namespaces referenced by the given Element or its descendants are declared by
the given Element or one of its descendants.
|
private static void |
rootNamespaces(org.w3c.dom.Element domElement,
org.w3c.dom.Element upperNamespaceSearchBound)
Recursively called function that ensures all the visibly used namespaces referenced by the given Element or its
descendants are declared if they don't appear in the list of already resolved namespaces.
|
public static void appendNamespaceDeclaration(@Nonnull
org.w3c.dom.Element element,
@Nonnull
java.lang.String namespaceURI,
@Nullable
java.lang.String prefix)
element - the element to add the attribute tonamespaceURI - the URI of the namespace. Cannot be null or empty (semantics would be undefined)prefix - the prefix for the namespace. If this is null this is the default namespace being added.@Nullable
public static java.lang.String lookupNamespaceURI(@Nonnull
org.w3c.dom.Element startingElement,
@Nullable
org.w3c.dom.Element stoppingElement,
@Nonnull
java.lang.String prefix)
Node.lookupNamespaceURI(java.lang.String) in that it only returns those namespaces actually declared
by an xmlns attribute. The Node method also checks the namespace a particular node was created in by
way of a call like Document.createElementNS(java.lang.String, java.lang.String) even if the
resulting element doesn't have a namespace declaration attribute.startingElement - the starting elementstoppingElement - the ancestor of the starting element that serves as the upper-bound, inclusive, for the
searchprefix - the prefix to look up. If null then the default namespace is returned.@Nullable
public static java.lang.String lookupPrefix(@Nonnull
org.w3c.dom.Element startingElement,
@Nullable
org.w3c.dom.Element stopingElement,
@Nullable
java.lang.String namespaceURI)
Node.lookupPrefix(java.lang.String) in that only those namespaces declared by an xmlns attribute
are inspected. The Node method also checks the namespace a particular node was created in by way of a
call like Document.createElementNS(java.lang.String, java.lang.String) even if the resulting
element doesn't have a namespace delcaration attribute.
Note:The prefix returned may not necessarily refer to the corresponding namespace within this element (if, for instance the prefix is associated with different namespaces at different points of the hierarchy.
startingElement - the starting elementstopingElement - the ancestor of the starting element that serves as the upper-bound, inclusive, for the
searchnamespaceURI - the uri to look uppublic static void rootNamespaces(@Nullable
org.w3c.dom.Element domElement)
domElement - the element to act as the root of the namespace declarationsprivate static void rootNamespaces(@Nullable
org.w3c.dom.Element domElement,
@Nullable
org.w3c.dom.Element upperNamespaceSearchBound)
domElement - the ElementupperNamespaceSearchBound - the "root" element of the fragment where namespaces may be rooted