Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

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

public class Main {

    public static Element childNodeByTag(Node node, String childNodeName) {
        if (node == null)
            return null;

        Element childElement = null;
        Node childNode = node.getFirstChild();
        if (childNode != null) {
            do {
                if (childNode.getNodeType() == Node.ELEMENT_NODE
                        && (childNodeName == null || childNodeName.equals(childNode.getNodeName()))) {
                    return (Element) childNode;
                }
            } while ((childNode = childNode.getNextSibling()) != null);
        }

        return null;
    }
}