Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

public class Main {
    public static Element getSingleElementByName(Node node, String name) {
        NodeList nodeList = node.getChildNodes();
        int count = nodeList.getLength();
        for (int i = 0; i < count; i++) {
            Node child = nodeList.item(i);
            if (child instanceof Element && child.getNodeName().equals(name)) {
                return (Element) child;
            }
        }
        return null;
    }
}