Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import org.w3c.dom.Node;

public class Main {
    /**
     * Gets the previous comment.
     * 
     * @param element
     *            the element
     * @return the previous comment
     */
    public static String getPreviousComment(Node element) {
        while (element.getPreviousSibling() != null) {
            Node prev = element.getPreviousSibling();
            if (prev.getNodeType() == Node.COMMENT_NODE) {
                return prev.getTextContent();
            } else if (prev.getNodeType() == Node.TEXT_NODE) {
                return getPreviousComment(prev);
            } else if (prev.getNodeType() == Node.ELEMENT_NODE) {
                return null;
            }
        }
        return null;
    }
}