Java XML Node Value Check isNode(Object value, String nodeName)

Here you can find the source of isNode(Object value, String nodeName)

Description

Returns true if the user object is an XML node with the specified type and and the optional attribute has the specified value or is not specified.

License

Open Source License

Parameter

Parameter Description
value Object that should be examined as a node.
nodeName String that specifies the node name.

Return

Returns true if the node name of the user object is equal to the given type.

Declaration


public static boolean isNode(Object value, String nodeName) 

Method Source Code

//package com.java2s;

import org.w3c.dom.Element;

public class Main {
    /**/*from  w w w . jav  a  2  s .  c  o  m*/
     * Returns true if the user object is an XML node with the specified type
     * and and the optional attribute has the specified value or is not
     * specified.
     * 
     * @param value
     *            Object that should be examined as a node.
     * @param nodeName
     *            String that specifies the node name.
     * @return Returns true if the node name of the user object is equal to the
     *         given type.
     */

    public static boolean isNode(Object value, String nodeName) {
        return isNode(value, nodeName, null, null);
    }

    /**
     * Returns true if the given value is an XML node with the node name and if
     * the optional attribute has the specified value.
     * 
     * @param value
     *            Object that should be examined as a node.
     * @param nodeName
     *            String that specifies the node name.
     * @param attributeName
     *            Optional attribute name to check.
     * @param attributeValue
     *            Optional attribute value to check.
     * @return Returns true if the value matches the given conditions.
     */
    public static boolean isNode(Object value, String nodeName,
            String attributeName, String attributeValue) {
        if (value instanceof Element) {
            Element element = (Element) value;

            if (nodeName == null
                    || element.getNodeName().equalsIgnoreCase(nodeName)) {
                String tmp = (attributeName != null) ? element
                        .getAttribute(attributeName) : null;

                return attributeName == null
                        || (tmp != null && tmp.equals(attributeValue));
            }
        }

        return false;
    }
}

Related

  1. isInsertNode(Node n)
  2. isJunk(Node node)
  3. isLeaf(Node node)
  4. isMixed(org.w3c.dom.Node node)
  5. isNamedElement(final Node aNode)
  6. isNodeAfter(Node node1, Node node2)
  7. isNodeNameEquals(Node node, String desiredName)
  8. isNodeTheSame(Node node1, Node node2)
  9. isNodeTypeElement(Node node)