Java tutorial
//package com.java2s; import org.w3c.dom.Node; public class Main { /** * Gets the next comment. * * @param element * the element * @return the next comment */ public static String getNextComment(Node element) { while (element.getNextSibling() != null) { Node prev = element.getNextSibling(); if (prev.getNodeType() == Node.COMMENT_NODE) { return prev.getTextContent(); } else if (prev.getNodeType() == Node.TEXT_NODE) { return getNextComment(prev); } else if (prev.getNodeType() == Node.ELEMENT_NODE) { return null; } } return null; } }