is XML Element Node Exist - Android XML

Android examples for XML:XML Node

Description

is XML Element Node Exist

Demo Code

/*L//  w  w w  .  j a  v a  2  s  .c o 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.
 */
//package com.java2s;
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 Tutorials