get Sub XML Element - Java XML

Java examples for XML:DOM Element

Description

get Sub XML Element

Demo Code


//package com.java2s;

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

public class Main {
    private static Node getSubElement(Node parent, String name) {
        NodeList nodes = ((Element) parent).getElementsByTagName(name);
        if (nodes.getLength() == 0) {
            return null;
        }//from   w  w  w .  j  a  va 2s.c  om
        return nodes.item(0);
    }
}

Related Tutorials