Java XML Node Namespace matches(final Node node, final boolean useNamespaces, final String namespaceURI, final String localName)

Here you can find the source of matches(final Node node, final boolean useNamespaces, final String namespaceURI, final String localName)

Description

Tests whether the given Node matches the specified name.

License

Open Source License

Parameter

Parameter Description
node the Node to test (must not be <code>null</code>)
useNamespaces <code>true</code> for namespaces mode
namespaceURI the namespace URI to match, <code>null</code> to match no namespace, <code>*</code> to match any namespace (ignored if <code>useNamespaces</code> is <code>false</code>)
localName <code>null</code> or <code>*</code> to match any node, matches the node name if <code>useNamespaces</code> is <code>false</code>, matches the local name if <code>useNamespaces</code> is <code>true</code>

Return

true if the matches the criteria

Declaration

private static boolean matches(final Node node, final boolean useNamespaces, final String namespaceURI,
        final String localName) 

Method Source Code

//package com.java2s;
// Licensed under the MIT license. See License.txt in the repository root.

import org.w3c.dom.Node;

public class Main {
    /**/*from   ww w  .j  a va  2  s . c om*/
     * Tests whether the given {@link Node} matches the specified name. No
     * <code>null</code> checking is done of the <code>node</code> argument.
     *
     * @param node
     *        the {@link Node} to test (must not be <code>null</code>)
     * @param useNamespaces
     *        <code>true</code> for namespaces mode
     * @param namespaceURI
     *        the namespace URI to match, <code>null</code> to match no
     *        namespace, <code>*</code> to match any namespace (ignored if
     *        <code>useNamespaces</code> is <code>false</code>)
     * @param localName
     *        <code>null</code> or <code>*</code> to match any node, matches the
     *        node name if <code>useNamespaces</code> is <code>false</code>,
     *        matches the local name if <code>useNamespaces</code> is
     *        <code>true</code>
     * @return <code>true</code> if the {@link Node} matches the criteria
     */
    private static boolean matches(final Node node, final boolean useNamespaces, final String namespaceURI,
            final String localName) {
        if (useNamespaces) {
            if (namespaceURI == null && node.getNamespaceURI() != null) {
                return false;
            }

            if (namespaceURI != null && !namespaceURI.equals("*") && !namespaceURI.equals(node.getNamespaceURI())) //$NON-NLS-1$
            {
                return false;
            }
        }

        if (localName == null || localName.equals("*")) //$NON-NLS-1$
        {
            return true;
        }

        if (useNamespaces) {
            return localName.equals(node.getLocalName());
        }

        return localName.equals(node.getNodeName());
    }
}

Related

  1. isNamespaceElement(Node node, String namespace)
  2. isNamespaceElement(Node node, String namespace)
  3. isNonDefaultNamespace(Node node)
  4. isSameNamespace(Node node, String namespace)
  5. match(final Node node, final String namespace, final String localname)
  6. matches(Node n, String namespace, String tagName)
  7. parseStaticInterface(String interfaceName, Node module, String nameSpace, PrintWriter out)
  8. removeNamedItemNS(final NamedNodeMap nodeMap, final String namespaceURI, final String localName)