Collect this node and its child nodes into a list, provided the node
satisfies the filtering criteria.
This mechanism allows powerful filtering code to be written very
easily, without bothering about collection of embedded tags separately.
e.g. when we try to get all the links on a page, it is not possible to
get it at the top-level, as many tags (like form tags), can contain
links embedded in them. We could get the links out by checking if the
current node is a
org.htmlparser.tags.CompositeTag, and going
through its children. So this method provides a convenient way to do
this.
Using collectInto(), programs get a lot shorter. Now, the code to
extract all links from a page would look like:
NodeList list = new NodeList ();
NodeFilter filter = new TagNameFilter ("A");
for (NodeIterator e = parser.elements (); e.hasMoreNodes ();)
e.nextNode ().collectInto (list, filter);
Thus,
list
will hold all the link nodes, irrespective of how
deep the links are embedded.
Another way to accomplish the same objective is:
NodeList list = new NodeList ();
NodeFilter filter = new TagClassFilter (LinkTag.class);
for (NodeIterator e = parser.elements (); e.hasMoreNodes ();)
e.nextNode ().collectInto (list, filter);
This is slightly less specific because the LinkTag class may be
registered for more than one node name, e.g. <LINK> tags too.