开发者

take all nodes of one type when i parse

开发者 https://www.devze.com 2023-02-11 22:15 出处:网络
I\'m creating a parser and I use the expression //html/body//div[@id=\'bodyContent\']/s[1] to take the first node with tag <p>.

I'm creating a parser and I use the expression //html/body//div[@id='bodyContent']/s[1] to take the first node with tag <p>.

But if I have to take all nodes, wh开发者_如何学Goat expression should I write?

Thanks


You want to extract all <p> tags within div with id bodyContent?

//html/body//div[@id='bodyContent']//p

or just all <p> tags?

//p

For instance, jaxen is a good library for xpath. You can use e.g.,

List<Node> nodes = new DOMXPath("//p").selectNodes(document);
for (Node node : nodes) {
    // do something with the matched nodes
    node.getValue();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消