A link is not text. Is the word "next" in a Text node within the link
children? Then you need a HasChildFilter (with the recursive option if
it's not a direct child).
You also need an AndFilter because you have two conditions.
NodeFilter linkFilter = new TagNameFilter ("A");
NodeFilter nextFilter = new StringFilter ("next");
NodeFilter andFilter = new AndFilter (linkfilter, new HasChildFilter
(nextFilter, true));
NodeList next = links.extractAllNodesThatMatch (andFilter);
This gives you the link node(s). If you actually want the text itself, use:
new AndFilter (nextfilter, new HasParentFilter (linkFilter, true));
Cibi wrote:
> How to extract specific link? for example "next" link.
>
> I use this and it return empty node:
>
> NodeFilter linkFilter = new TagNameFilter("A");
> NodeFilter nextFilter = new StringFilter("next");
> NodeList links = parser.extractAllNodesThatMatch(linkFilter);
> NodeList next = links.extractAllNodesThatMatch(nextFilter);
>
> do I need to loop thought link notelist then compare each node?
>
> Thanks
>
>
|