?
Solved

parsing question

Posted on 2004-09-02
4
Medium Priority
?
165 Views
Last Modified: 2010-03-31
hi im trying to get a simple parser going below is my bit of code, I m to read all the contents of an url and store it in a database, the question is how do i know when i reached the end of a page? so that i know when to store everything in my database and move on to the next link

 public void handleStartTag(HTML.Tag t,MutableAttributeSet a, int p)
{  
               if (t == HTML.Tag.A)
      {
                 ahreflink = (String)a.getAttribute(HTML.Attribute.HREF);
                 searchList.add(ahreflink);

                }
      
          if (t == HTML.Tag.TITLE)
                 {    
                  titleFlag=true;
                  }


}

            public void handleText(char[] data, int pos)
            {         
            try{
                title = new String(data);
                content =new String(data);
                  
                  if(titleFlag==false)
                    {                        
                       text = text + " " + content;                   
                  }      
            
                        if(titleFlag==true)
                        {
                         System.out.println("Title: "+ title);
                         titleFlag=false;
                        }

                  }catch(Exception p){p.printStackTrace();}                          
            }//end of handleText


0
Comment
Question by:HomerrSimpson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Assisted Solution

by:primusmagestri
primusmagestri earned 60 total points
ID: 11962861
Look for the html end tag: </html>. After this tag you can, at most, have some comments.
0
 
LVL 35

Accepted Solution

by:
TimYates earned 240 total points
ID: 11962896
public void handleEndTag( HTML.Tag t, int pos )
0
 

Author Comment

by:HomerrSimpson
ID: 11963108
do you mean something like

public void handleEndTag(HTML.Tag t, int pos)
{
   if (t == HTML.Tag.HTML)
     {

    store "text" in database
    }



}
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11963367
yup...that should do it...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month8 days, 1 hour left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question