import java.io.IOException; import nu.xom.*; public class CommentReader { public static void list(Node node) { for (int i = 0; i < node.getChildCount(); i++) { Node child = node.getChild(i); if (child instanceof Comment) { System.out.println(child.toXML()); } else { list(child); } } } public static void main(String[] args) { if (args.length <= 0) { System.out.println("Usage: java CommentReader URL"); return; } try { Builder parser = new Builder(); Document doc = parser.build(args[0]); list(doc); } catch (ParsingException ex) { System.out.println(args[0] + " is not well-formed."); System.out.println(ex.getMessage()); } catch (IOException ex) { System.out.println( "Due to an IOException, the parser could not read " + args[0] ); } } }