Results 1 to 2 of 2
  1. #1
    paty is offline Member
    Join Date
    Jul 2007
    Posts
    41
    Rep Power
    0

    Default How to parse in html

    I want to parse a HTML file, I need to parse through the file until I encounter the second table in the file and then display the contents of that particular table.

    any ideas?

  2. #2
    Heather is offline Senior Member
    Join Date
    Jun 2007
    Posts
    164
    Rep Power
    8

    Default

    try this:
    Java Code:
    import java.io.*;
    import javax.swing.text.*;
    import javax.swing.text.html.*;
    import javax.swing.text.html.parser.*;
    
    public class SEMMParse {
      //........
     private class CallbackHandler extends HTMLEditorKit.ParserCallback 
     {
       public void handleStartTag( HTML.Tag t,
                MutableAttributeSet a,
                int pos) {
        if (t==HTML.Tag.A && a!=null)
        { 
            //do something with 'A' tags
        }
       }
        public void handleText( char[] data, int pos) {
          //do something
        }
        public void handleEndTag( HTML.Tag t, int pos) {
        }
    }//end CallbackHandler
    //.......
        //... somemethod()
        try {
         BufferedReader  reader = 
    	new BufferedReader(new FileReader(path));
    			
         new ParserDelegator().parse
    	( reader, new CallbackHandler(), true );
         }
         catch (IOException ioe) {ioe.printStackTrace(); }
    }
    }

Similar Threads

  1. how to Parse int to a string variable
    By raj reddy in forum Java Servlet
    Replies: 10
    Last Post: 01-09-2009, 08:41 PM
  2. SAX Parse
    By bluefloyd8 in forum New To Java
    Replies: 1
    Last Post: 01-25-2008, 04:57 PM
  3. how to parse an xml file
    By oregon in forum XML
    Replies: 3
    Last Post: 08-01-2007, 05:53 PM
  4. Parse error
    By Eric in forum Advanced Java
    Replies: 2
    Last Post: 07-01-2007, 07:32 PM
  5. How to parse HTML tags
    By Ada in forum Advanced Java
    Replies: 1
    Last Post: 05-31-2007, 10:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •