Java XML Node Namespace isNonDefaultNamespace(Node node)

Here you can find the source of isNonDefaultNamespace(Node node)

Description

is Non Default Namespace

License

Open Source License

Declaration

public static boolean isNonDefaultNamespace(Node node) 

Method Source Code

//package com.java2s;
/**//from  ww  w. j  ava  2  s .  c  o  m
 * (The MIT License)
 *
 * Copyright (c) 2008 - 2014:
 *
 * * {Aaron Patterson}[http://tenderlovemaking.com]
 * * {Mike Dalessio}[http://mike.daless.io]
 * * {Charles Nutter}[http://blog.headius.com]
 * * {Sergio Arbeo}[http://www.serabe.com]
 * * {Patrick Mahoney}[http://polycrystal.org]
 * * {Yoko Harada}[http://yokolet.blogspot.com]
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * 'Software'), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

import org.w3c.dom.Node;

public class Main {
    public static final String XMLNS_URI = "http://www.w3.org/2000/xmlns/";

    public static boolean isNonDefaultNamespace(Node node) {
        return (isNamespace(node) && !"xmlns".equals(node.getNodeName()));
    }

    public static boolean isNamespace(Node node) {
        return (XMLNS_URI.equals(node.getNamespaceURI()) || isNamespace(node
                .getNodeName()));
    }

    public static boolean isNamespace(String nodeName) {
        return (nodeName.startsWith("xmlns"));
    }

    public static String getNodeName(Node node) {
        if (node == null) {
            System.out.println("node is null");
            return "";
        }
        String name = node.getNodeName();
        if (name == null) {
            System.out.println("name is null");
            return "";
        }
        if (name.equals("#document")) {
            return "document";
        } else if (name.equals("#text")) {
            return "text";
        } else {
            name = getLocalPart(name);
            return (name == null) ? "" : name;
        }
    }

    /**
     * Return the local part of a qualified name like "prefix:local".
     * Returns <code>qName</code> if there is no prefix.
     */
    public static String getLocalPart(String qName) {
        if (qName == null)
            return null;

        int pos = qName.indexOf(':');
        if (pos > 0)
            return qName.substring(pos + 1);
        else
            return qName;
    }
}

Related

  1. isInNamespace(Node node, String namespace)
  2. isInNamespace(Node node, String namespace)
  3. isNamespace(Node node)
  4. isNamespaceElement(Node node, String namespace)
  5. isNamespaceElement(Node node, String namespace)
  6. isSameNamespace(Node node, String namespace)
  7. match(final Node node, final String namespace, final String localname)
  8. matches(final Node node, final boolean useNamespaces, final String namespaceURI, final String localName)
  9. matches(Node n, String namespace, String tagName)