Java XML Node Value Check isElementNodeExist(Node root, String nodeString)

Here you can find the source of isElementNodeExist(Node root, String nodeString)

Description

is Element Node Exist

License

BSD License

Declaration

public static boolean isElementNodeExist(Node root, String nodeString) 

Method Source Code


//package com.java2s;
/*L//from w  ww.ja  va 2 s.  co m
 *  Copyright SAIC, Ellumen and RSNA (CTP)
 *
 *
 *  Distributed under the OSI-approved BSD 3-Clause License.
 *  See http://ncip.github.com/national-biomedical-image-archive/LICENSE.txt for details.
 */

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static boolean isElementNodeExist(Node root, String nodeString) {
        NodeList nlist = root.getChildNodes();

        for (int i = 0; i < nlist.getLength(); i++) {
            if (nlist.item(i) instanceof Element) {
                if (nlist.item(i).getNodeName().equalsIgnoreCase(nodeString)) {
                    return true;
                }

                if (nlist.item(i).hasChildNodes() && isElementNodeExist(nlist.item(i), nodeString)) {
                    return true;
                }
            }
        }

        return false;
    }
}

Related

  1. isCommentAllowed(Node node)
  2. isCommentNode(Node node)
  3. isContainerElement(Node node)
  4. isCreateInstanceSet(Node node)
  5. isElementNodeOfType(final Node n, final String type)
  6. isElementType(Node _node)
  7. isEmpty(Node node)
  8. isEmptyTag(Node p_node)