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 getAttributeValue(Node node, String attribute) {
        Node _node = node.getAttributes().getNamedItem(attribute);
        return getNodeValue(_node);
    }

    public static String getNodeValue(Node node) {
        if (node == null) {
            return null;
        } else if (node instanceof Text) {
            return node.getNodeValue().trim();
        } else if (node instanceof Element) {
            node.normalize();
            Node temp = node.getFirstChild();
            if (temp != null && (temp instanceof Text))
                return temp.getNodeValue().trim();
            else
                return "";
        } else {
            return node.getNodeValue().trim();
        }
    }
}