get Child from XML Node - Java XML

Java examples for XML:XML Node Child

Description

get Child from XML Node

Demo Code


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

public class Main {
    public static Node getChild(Node node, String tag) {
        NodeList nodes = node.getChildNodes();
        for (int i = 0; i < nodes.getLength(); i++) {
            Node item = nodes.item(i);
            if (item.getNodeName().equals(tag))
                return item;
        }/*from  w w  w. j  a  va 2s . c  om*/
        return null;
    }
}

Related Tutorials