get First XML Child Element - Java XML

Java examples for XML:XML Element Child

Description

get First XML Child Element

Demo Code


//package com.java2s;

import org.w3c.dom.Element;

public class Main {
    public static Element getFirstChildElement(Element parent,
            String childName) {/*from w  w w .j  ava  2 s .c  o m*/
        if (parent.getElementsByTagName(childName).getLength() > 0) {
            return (Element) parent.getElementsByTagName(childName).item(0);
        }
        return null;
    }
}

Related Tutorials