[英]JSoup - Select all comments
我想使用JSoup从文档中选择所有注释。 我想做这样的事情:
for(Element e : doc.select("comment")) {
System.out.println(e);
}
我已经试过了:
for (Element e : doc.getAllElements()) {
if (e instanceof Comment) {
}
}
但是在日食“不兼容的条件操作数类型元素和注释”中发生以下错误。
干杯,
皮特
由于Comment extends Node
您需要将instanceof
应用于节点对象,而不是元素,如下所示:
for(Element e : doc.getAllElements()){
for(Node n: e.childNodes()){
if(n instanceof Comment){
System.out.println(n);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.