Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

public class Main {
    public static String getTextofChildNode(Node parentNode, String nameOfChildToFind) {
        Node nodeToFind = getChildNodebyName(parentNode, nameOfChildToFind);
        if (nodeToFind != null)
            return nodeToFind.getTextContent();
        else
            return "";
    }

    public static Node getChildNodebyName(Node parentNode, String nameOfChildToFind) {
        NodeList childNodes = parentNode.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node currentChildNode = childNodes.item(i);
            String childName = currentChildNode.getLocalName();
            if (childName != null)
                if (childName.equals(nameOfChildToFind))
                    return currentChildNode;
        }
        return null;
    }
}