get Child XML Element By Tag Name - Java XML

Java examples for XML:XML Element Child

Description

get Child XML Element By Tag Name

Demo Code


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

public class Main {
    public static Element getChildElementByTagName(Element e, String tagName) {
        NodeList l = e.getElementsByTagName(tagName);
        Element el = null;//from w  w  w .ja  v a  2 s.c  o m
        if (l.getLength() > 0) {
            el = (Element) l.item(0);
        }
        return el;
    }
}

Related Tutorials