Reputation:
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
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
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
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