Re: [Htmlparser-user] HTML tree creation
Brought to you by:
derrickoswald
From: Ian M. <ian...@gm...> - 2007-02-28 16:35:30
|
Have a look at the NodeTreeWalker class. It includes a depth-first (how you'd probably want to do it) iteration option, so you can go to the root node and simply call next and then print out the name of the current element. As it works on a Node, if the root has multiple nodes (common if there is a doctype and some other text spacing), you get a NodeList - you can simply iterate through the Nodes of the root NodeList and perform the above on each one. Ian On 16 Feb 2007 02:20:16 -0000, Dipesh Sharma <dip...@re...> wrote: > > Hi there, > > I'm trying to build an HTML tree model using your parser. I have come up > with this code so far: > > import org.htmlparser.Parser; > import org.htmlparser.util.NodeList; > import org.htmlparser.util.ParserException; > import org.htmlparser.parserapplications.filterbuilder.HtmlTreeModel; > > > > class Test > { > public static void main (String[] args) > { > try > { > Parser parser = new Parser ("http://www.deals2buy.com") > NodeList list = parser.parse (null); > HtmlTreeModel Tree= new HtmlTreeModel(list); > System.out.println (Tree.toString()); > } > catch (ParserException pe) > { > pe.printStackTrace (); > } > } > } > > > However toString method simply prints the objects name. Could you please > help me with a solution that prints out the whole HTML tree? > > Thanks, > Chikki > > > <http://adworks.rediff.com/cgi-bin/AdWorks/sigclick.cgi/www.rediff.com/signature-home.htm/1507191490@Middle5?PARTNER=3> > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share > your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Htmlparser-user mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/htmlparser-user > > |