[Htmlparser-cvs] htmlparser/src/org/htmlparser/util NodeList.java,1.57,1.58
Brought to you by:
derrickoswald
From: Derrick O. <der...@us...> - 2005-03-12 13:39:56
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21713/util Modified Files: NodeList.java Log Message: RFE #1160345 NodeList.visitAllNodesWith Added visitAllNodesWith to the NodeList class. Index: NodeList.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util/NodeList.java,v retrieving revision 1.57 retrieving revision 1.58 diff -C2 -d -r1.57 -r1.58 *** NodeList.java 13 Feb 2005 20:36:03 -0000 1.57 --- NodeList.java 12 Mar 2005 13:39:47 -0000 1.58 *************** *** 33,36 **** --- 33,37 ---- import org.htmlparser.NodeFilter; import org.htmlparser.filters.NodeClassFilter; + import org.htmlparser.visitors.NodeVisitor; public class NodeList implements Serializable { *************** *** 301,303 **** --- 302,327 ---- return (extractAllNodesThatMatch (new NodeClassFilter (classType), recursive)); } + + /** + * Utility to apply a visitor to a node list. + * Provides for a visitor to modify the contents of a page and get the + * modified HTML as a string with code like this: + * <pre> + * Parser parser = new Parser ("http://whatever"); + * NodeList list = parser.parse (null); // no filter + * list.visitAllNodesWith (visitor); + * System.out.println (list.toHtml ()); + * </pre> + */ + public void visitAllNodesWith (NodeVisitor visitor) + throws + ParserException + { + Node node; + + visitor.beginParsing (); + for (int i = 0; i < size; i++) + nodeData[i].accept (visitor); + visitor.finishedParsing (); + } } |