Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import org.w3c.dom.*;

public class Main {
    public static String getElementValue(Node elem) {
        if ((elem != null) && (elem.hasChildNodes())) {
            for (Node kid = elem.getFirstChild(); kid != null; kid = kid.getNextSibling()) {
                if (kid.getNodeType() == Node.TEXT_NODE) {
                    return kid.getNodeValue();
                }
            }
        }
        return "";
    }

    public static String getElementValue(Node node, String nodeName) {
        NodeList children = node.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            if ((child.getNodeType() == Node.ELEMENT_NODE) && (child.getNodeName().equals(nodeName)))
                return getElementValue(child);
        }
        return null;
    }
}