find XML Root Node from NodeList - Java XML

Java examples for XML:XML Node

Description

find XML Root Node from NodeList

Demo Code


//package com.java2s;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    static Node findRootNode(NodeList aNodeList, String nodeName) {
        for (int count = 0; count < aNodeList.getLength(); ++count) {

            Node tempNode = aNodeList.item(count);
            if (tempNode.getNodeType() == Node.ELEMENT_NODE) {
                if (tempNode.getNodeName().equals(nodeName)) {
                    return tempNode;
                }//  w  w  w.j  av  a 2 s .  co m
            }
        }
        return null;
    }
}

Related Tutorials