Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.List; import org.w3c.dom.Comment; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static List<Comment> getCommentNode(Node n) { List<Comment> commentList = new ArrayList<Comment>(); NodeList nodeList = n.getChildNodes(); if (nodeList == null) return null; for (int i = 0; i < nodeList.getLength(); i++) { Node ithNode = nodeList.item(i); if (ithNode instanceof Comment) { commentList.add((Comment) ithNode); } } return commentList; } }