【发布时间】:2015-09-13 00:11:08
【问题描述】:
我想检查 HTML 注释标签是否正确插入。如果有开始标签但没有结束标签,我想显示错误。
我引用了this link 并且能够检索到有效的评论节点
for(Element e : document.getAllElements()){
for(Node n: e.childNodes()){
if(n instanceof Comment){
commentNodes++;
System.out.println(n);
}
}
}
if(html.contains("<!--") && commentNodes == 0) {
System.out.println("error");
} else if(html.contains("-->") && commentNodes == 0) {
System.out.println("error1");
}
有更好的方法吗?
【问题讨论】: