Here you can find the source of isElementNodeExist(Node root, String nodeString)
public static boolean isElementNodeExist(Node root, String nodeString)
//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; } }