Java Utililty Methods XML Node Namespace

List of utility methods to do XML Node Namespace

Description

The list of methods to do XML Node Namespace are organized into topic(s).

Method

StringgetNamespaceURI(Node node)
get Namespace URI
return node.getNamespaceURI();
StringgetNamespaceUri(Node node)
Get the namespace URI of a given node.
String namespace = node.getNamespaceURI();
return (namespace != null) ? namespace : XMLConstants.NULL_NS_URI;
StringgetNamespaceURI(Node node)
get Namespace URI
return node.getNamespaceURI();
StringgetNameSpaceUri(Node node, String content, String namespaceURI)
get Name Space Uri
if (namespaceURI == null) {
    namespaceURI = node.lookupNamespaceURI(content.substring(0, content.indexOf(":")));
return namespaceURI;
StringgetNamespaceURI(Node node, String searchPrefix)
get Namespace URI
return node.lookupNamespaceURI(searchPrefix);
StringgetNodeName(Node node, NamespaceContext namespaceContext)
Returns the node name using the prefixes defined in the given namespace context rather than the prefixes used in the parsed XML.
if (node == null)
    return null;
String name = node.getNodeName();
if (name.startsWith("xmlns:")) {
    String uri = node.getNodeValue();
    if (uri != null && namespaceContext != null) {
        String prefix = namespaceContext.getPrefix(uri);
        if (prefix != null) {
...
StringgetNodeString(Node node, NamespaceContext context)
Builds an XPath string referencing the given node relative to it's parent.
if (node == null) {
    return null;
String nodeName = node.getLocalName();
if (nodeName == null)
    nodeName = node.getNodeName();
if (node.getNamespaceURI() != null) {
    String prefix = context.getPrefix(node.getNamespaceURI());
...
booleanhasDITANamespace(Node node)
has DITA Namespace
String uri = node.getNamespaceURI();
return (uri == null || DITAC_NS_URI.equals(uri));
booleanhasNamespace(Node node, String prefix, String namespace)
has Namespace
if (namespace == null) {
    return true;
String attrName;
if (prefix != null && prefix.length() > 0) {
    attrName = "xmlns:" + prefix;
} else {
    attrName = "xmlns";
...
booleanhasNamespaceURI(@Nullable final Node aNode, @Nullable final String sNamespaceURI)
has Namespace URI
final String sNSURI = aNode == null ? null : aNode.getNamespaceURI();
return sNSURI != null && sNSURI.equals(sNamespaceURI);