user3181223
user3181223

Reputation:

reading html file line by line using java

I want to read a html file line and line and need to store the elements .for textbox i have to store the id,name,type attribute values into some collection. In the same i need to get attributes for checkbox, radiobox etc

Is their any API to parse the html file line by line.

Upvotes: 0

Views: 962

Answers (4)

Jaykumar Patel
Jaykumar Patel

Reputation: 27624

Use Class StringBuilder

 StringBuilder contentBuilder = new StringBuilder();
 try {
      BufferedReader in = new BufferedReader(new FileReader("mypage.html"));
      String str;
      while ((str = in.readLine()) != null) {
          contentBuilder.append(str);
      }
      in.close();
 } catch (IOException e) {
      System.err.println("HTML File Read Error: " + e.getMessage());
 }
 String content = contentBuilder.toString();

Upvotes: 1

Klemens Morbe
Klemens Morbe

Reputation: 653

You can use a DOM Parser and read all Elements and Attributes. Or you could use this library(jsoup) which is based on the DOM Parser.

Upvotes: 2

Hirak
Hirak

Reputation: 3649

NekoHTML is one of the many html parsers that you could use.

Upvotes: 0

Aaron Digulla
Aaron Digulla

Reputation: 328860

No, since that doesn't make sense: HTML has no useful notion of "line". What you need to do is read the HTML element by element.

There are lots of parsers for XML but HTML is a more lenient, so you need a special parser for it. Try JTidy.

Upvotes: 0

Related Questions