Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

public class Main {
    /**
     * Gets the value of the first child element of parent
     * 
     * @param childName
     * @param parent
     * @return
     */
    public static String getFirstChildValue(String childName, Element parent) {
        return getElementValue(parent.getElementsByTagName(childName).item(0));
    }

    public static String getFirstChildValue(String childName, Document parent) {
        return getElementValue(parent.getElementsByTagName(childName).item(0));
    }

    public static String getElementValue(Node element) {
        return getElementValue((Element) element);
    }

    public static String getElementValue(Element element) {
        return element.getChildNodes().item(0).getNodeValue();
    }
}