get XML Sub Node - Java XML

Java examples for XML:XML Node Child

Description

get XML Sub Node

Demo Code


//package com.java2s;

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

public class Main {

    public static final Node getSubNode(Node n, String tag) {
        int i;/*from  ww  w.j  a  v  a  2 s . co m*/
        NodeList children;
        Node childnode;

        if (n == null)
            return null;

        children = n.getChildNodes();
        for (i = 0; i < children.getLength(); i++) {
            childnode = children.item(i);
            if (childnode.getNodeName().equalsIgnoreCase(tag)) {
                return childnode;
            }
        }
        return null;
    }
}

Related Tutorials